上篇博文已经介绍了MySQL 5.7版本的GTID复制模式的搭建,下面操做将GTID复制转换成传统复制模式。mysql
类型 | ip | prot | server-id |
---|---|---|---|
master | 192.168.56.100 | 3307 | 1003307 |
slave | 192.168.56.200 | 3307 | 2003307 |
root@localhost [(none)] 09:38:41>stop slave
记录Relay_Master_Log_File
和Exec_Master_Log_Pos
信息。web
root@localhost [(none)] 09:41:22>show slave status\G *************************** 1. row *************************** Slave_IO_State: Master_Host: 192.168.56.100 Master_User: repl Master_Port: 3307 Connect_Retry: 60 Master_Log_File: my3307_binlog.000005 Read_Master_Log_Pos: 194 Relay_Log_File: mysqldb2-relay-bin.000010 Relay_Log_Pos: 375 Relay_Master_Log_File: my3307_binlog.000005 Slave_IO_Running: No Slave_SQL_Running: No Replicate_Do_DB: Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Errno: 0 Last_Error: Skip_Counter: 0 Exec_Master_Log_Pos: 194 Relay_Log_Space: 585 Until_Condition: None Until_Log_File: Until_Log_Pos: 0 Master_SSL_Allowed: No Master_SSL_CA_File: Master_SSL_CA_Path: Master_SSL_Cert: Master_SSL_Cipher: Master_SSL_Key: Seconds_Behind_Master: NULL Master_SSL_Verify_Server_Cert: No Last_IO_Errno: 0 Last_IO_Error: Last_SQL_Errno: 0 Last_SQL_Error: Replicate_Ignore_Server_Ids: Master_Server_Id: 1003307 Master_UUID: 3a068bf8-cdeb-11e8-8176-080027b0b461 Master_Info_File: mysql.slave_master_info SQL_Delay: 0 SQL_Remaining_Delay: NULL Slave_SQL_Running_State: Master_Retry_Count: 86400 Master_Bind: Last_IO_Error_Timestamp: Last_SQL_Error_Timestamp: Master_SSL_Crl: Master_SSL_Crlpath: Retrieved_Gtid_Set: Executed_Gtid_Set: 3a068bf8-cdeb-11e8-8176-080027b0b461:1-12 Auto_Position: 1 Replicate_Rewrite_DB: Channel_Name: Master_TLS_Version: 1 row in set (0.00 sec)
根据上面记录的Relay_Master_Log_File
和Exec_Master_Log_Pos
信息,change master:sql
root@localhost [(none)] 09:41:26>change master to master_log_file='my3307_binlog.000005',master_log_pos=194,master_auto_position=0; Query OK, 0 rows affected (0.01 sec) #参数解释: master_auto_position=0 表示禁用master_auto_position
root@localhost [test] 09:51:28>start slave;
root@localhost [test] 09:55:01> set global gtid_mode=on_permissive; Query OK, 0 rows affected (0.01 sec) root@localhost [test] 09:55:25> set global gtid_mode=off_permissive; Query OK, 0 rows affected (0.01 sec) root@localhost [test] 09:55:58> set global gtid_mode=off; Query OK, 0 rows affected (0.01 sec) root@localhost [test] 09:56:09> set global enforce_gtid_consistency = 0; Query OK, 0 rows affected (0.00 sec) root@localhost [test] 09:57:34> show variables like '%gtid%'; +----------------------------------+-----------+ | Variable_name | Value | +----------------------------------+-----------+ | binlog_gtid_simple_recovery | ON | | enforce_gtid_consistency | OFF | | gtid_executed_compression_period | 1000 | | gtid_mode | OFF | | gtid_next | AUTOMATIC | | gtid_owned | | | gtid_purged | | | session_track_gtids | OFF | +----------------------------------+-----------+ 8 rows in set (0.01 sec) 能够把 gtid_mode=off 与 enforce_gtid_consistency=OFF 写入配置文件my.cnf中,重启以后也能生效。
此博文介绍了MySQL 5.7版本的传统复制模式的搭建,下面操做将传统复制转换成GTID复制模式。服务器
类型 | ip | prot | server-id |
---|---|---|---|
master | 192.168.56.100 | 3306 | 1003306 |
slave | 192.168.56.200 | 3306 | 2003306 |
在MySQL每一个实例上, 将enforce_gtid_consistency设置为warnsession
root@localhost [(none)] 10:21:01> set @@global.enforce_gtid_consistency=warn;
【注意】:执行完这条语句后,若是出现GTID不兼容的语句用法,会在error log记录相关信息,那么须要调整该程序避免不兼容的写法,直到彻底没有不兼容的语句。svg
在 2.2
完成后,若是没有不兼容语句,能够把MySQL每一个实例的ENFORCE_GTID_CONSISTENCY值设置为on。函数
root@localhost [(none)] 11:05:11> set @@global.enforce_gtid_consistency=on; Query OK, 0 rows affected (0.00 sec)
将全部MySQL实例的GTID模式设置为off_permissivespa
root@localhost [(none)] 11:06:55>SET @@GLOBAL.GTID_MODE = OFF_PERMISSIVE; Query OK, 0 rows affected (0.01 sec)
root@localhost [(none)] 11:12:20> SET @@GLOBAL.GTID_MODE = ON_PERMISSIVE; Query OK, 0 rows affected (0.01 sec)
检查从库Ongoing_anonymous_transaction_count状态值是否为0,若是为0,一味着没有等待的事务,能够进行下一步操做.net
root@localhost [(none)] 11:13:09>SHOW STATUS LIKE 'ONGOING_ANONYMOUS_TRANSACTION_COUNT'; +-------------------------------------+-------+ | Variable_name | Value | +-------------------------------------+-------+ | Ongoing_anonymous_transaction_count | 0 | +-------------------------------------+-------+ 1 row in set (0.00 sec)
root@localhost [(none)] 11:29:55>show slave status\G *************************** 1. row *************************** ... Relay_Master_Log_File: my3306_binlog.000090 ... Exec_Master_Log_Pos: 194 ... #在slave上使用函数: root@localhost [(none)] 11:30:01>SELECT MASTER_POS_WAIT('my3306_binlog.000090', 194); +----------------------------------------------+ | MASTER_POS_WAIT('my3306_binlog.000090', 194) | +----------------------------------------------+ | 0 | +----------------------------------------------+ 1 row in set (0.00 sec) 返回结果大于或等于0就说明匿名事务已经所有复制完成
root@localhost [(none)] 11:31:36>SET @@GLOBAL.GTID_MODE = ON; Query OK, 0 rows affected (0.01 sec)
root@localhost [(none)] 11:37:17>STOP slave; Query OK, 0 rows affected (0.00 sec) root@localhost [(none)] 11:37:24>change master to master_auto_position=1; Query OK, 0 rows affected (0.00 sec) root@localhost [(none)] 11:37:52>start slave; Query OK, 0 rows affected (0.00 sec)