https://dev.mysql.com/doc/refman/5.7/en/replication-gtids-howto.html
GTID(GlobalTransaction ID)是对于一个已提交事务的编号,并且是一个全局唯一的编号。GTID实际上是由UUID+TID组成的。其中UUID是一个MySQL实例的唯一标识。TID代表了该实例上已经提交的事务数量,并且随着事务提交单调递增。
设置gtid模式,在my.cnf里面的mysqld选项卡里面设置,设置完后,重启mysql服务生效:
[mysqld]
gtid_mode=ON
log-slave-updates=ON
enforce-gtid-consistency=ON
mysql> change master to
master_host=‘主库IP‘,
master_port=主库端口,
master_user=‘repl‘,
master_password=‘repl密码‘,
master_auto_position=1;
mysql> start slave;
PS:其中这里有差别,以前非gtid的是用master_log_file=‘mysql-bin.000009‘,master_log_pos=154;而gtid就采用了master_auto_positon=1;来自动同步主库的binlog了。
查看从库复制状态,是双YES,而且Seconds_Behind_Master: 0:
Tell the slave to use the master with GTID based transactions as the replication data source, and to use GTID-based auto-positioning rather than file-based positioning. Issue a CHANGE MASTER TO statement on the slave, including the MASTER_AUTO_POSITION option in the statement to tell the slave that the master‘s transactions are identified by GTIDs.
查看备机信息
1.主库show slave hosts;
搭建级联备库
新数据库改为与主库同步
reset slave;
change master to
master_host=‘主库IP‘,
master_port=主库端口,
master_user=‘repl‘,
master_password=‘repl密码‘,
master_auto_position=1;
知识点整理:
1、.mysql_history文件记录mysql用户执行的命令,存在安全隐患,需要进行软连接处理。lns -l /dev/null $HOME/.mysql_history
2、mysql 如何搭建半同步和异步备库。
3、mysql环境安装。注意修改/relay_log文件夹的属主,VIP配置。
原文地址:http://blog.51cto.com/7499131/2107922