文章目錄
- 環境
- 配置
環境
主機 IP 系統版本 角色
mysql01 192.168.17.131 CentOS Linux release 7.3 主
mysql02 192.168.17.132 CentOS Linux release 7.3 從
mysql03 192.168.17.134 CentOS Linux release 7.3 主
配置
1、主-192.168.17.131
[[email protected] ~]# vi /etc/my.cnf
server-id=101
log-bin=mysql-bin
gtid-mode=ON
enforce-gtid-consistency=ON
mysql> grant replication slave,replication client on *.* TO 'gtid'@'%' identified by '000000';
2、主-192.168.17.134
[[email protected] ~]# vi /etc/my.cnf
server-id=102
log-bin=mysql-bin
gtid-mode=ON
enforce-gtid-consistency=ON
mysql> grant replication slave,replication client on *.* TO 'gtid'@'%' identified by '000000';
3、從-192.168.17.132
[[email protected] ~]# vi /etc/my.cnf
server-id=103
gtid-mode=ON
enforce-gtid-consistency=ON
master_info_repository=table
relay_log_info_repository=table
mysql> CHANGE MASTER TO
MASTER_HOST='192.168.17.131',
MASTER_USER='gtid',
MASTER_PASSWORD='000000',
MASTER_AUTO_POSITION=1 FOR CHANNEL 'master1';
mysql> CHANGE MASTER TO
MASTER_HOST='192.168.17.134',
MASTER_USER='gtid',
MASTER_PASSWORD='000000',
MASTER_AUTO_POSITION=1 FOR CHANNEL 'master2';
mysql> start slave for channel 'master1';
mysql> start slave for channel 'master2';
注意:
清除slave和gtid資訊指令:
stop slave;
reset slave;
reset slave all; # 如果reset slave清楚不幹淨就執行該指令。它除了完成RESET SLAVE的動作,還清空了mysql.slave_master_info表,和删除了所有的複制通道(replication channel),然後又建立了預設通道。
reset master;