GTID复制转换为传统主从复制
切换操作非常简单,可以在线完成。
第一步:检查当前主从是否正常
主库:
mysql> show master status;
+------------------+----------+--------------+------------------+------------------------------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+------------------------------------------+
| mysql-bin.000012 | 737 | | | 5112a895-440a-11e9-b39b-005056986842:1-3 |
+------------------+----------+--------------+------------------+------------------------------------------+
1 row in set (0.00 sec)
从库:
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.20.5
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000012
Read_Master_Log_Pos: 737
Relay_Log_File: 18c-dg-relay-bin.000005
Relay_Log_Pos: 950
Relay_Master_Log_File: mysql-bin.000012
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
省略。。。
Replicate_Ignore_Server_Ids:
Master_Server_Id: 5
Master_UUID: 5112a895-440a-11e9-b39b-005056986842
Master_Info_File: /var/lib/mysql/master.info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set: 5112a895-440a-11e9-b39b-005056986842:1-3
Executed_Gtid_Set: 5112a895-440a-11e9-b39b-005056986842:1-3
Auto_Position: 1
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
1 row in set (0.00 sec)
从上面可以看出,当前主从状态正常。
第二步:停止SLAVE
mysql> stop slave;
第三步:从库执行CHANGE MASTER命令
和搭建普通主从一样,执行
change master命令
指定具体的binlog文件和position,如下:
mysql> change master to master_auto_position=0,master_host='192.168.20.5', master_port=3306,master_user='rep',master_password='mysql',Master_Log_File='mysql-binlog.000012',Master_Log_Pos=737;
第四步:从库启动SLAVE
mysql> START SLAVE;
注意:binlog文件和position要对应。
修改GTID相关的参数
主库:
mysql> set global gtid_mode='on_permissive';
mysql> set global gtid_mode='off_permissive';
mysql> set global enforce_gtid_consistency=off;
mysql> set global gtid_mode=off;
从库:
mysql> set global gtid_mode='on_permissive';
mysql> set global gtid_mode='off_permissive';
mysql> set global enforce_gtid_consistency=off;
mysql> set global gtid_mode=off;
验证
show master status;
show slave status\G