由于GTID的優勢,我們需要將傳統基于file-pos的復制更改為基于GTID的復制,如何在線變更成為我們關心的一個點,如下為具體的方法:
目前我們有一個傳統復制下的M-S結構:
port 3301 master
port 3302 slave
| master上(3301):[zejin] 3301>select * from t_users;+----+------+| id | name |+----+------+| 1 | hao || 2 | zhou |+----+------+rows in set (0.00 sec) slave上(3302):[zejin] 3302>show slave status/G*************************** 1. row ***************************Slave_IO_State: Waiting for master to send eventMaster_Host: 192.168.1.240Master_User: replMaster_Port: 3301Connect_Retry: 60Master_Log_File: binlog57.000002Read_Master_Log_Pos: 417Relay_Log_File: zejin240-relay-bin.000004Relay_Log_Pos: 628Relay_Master_Log_File: binlog57.000002Slave_IO_Running: YesSlave_SQL_Running: YesReplicate_Do_DB:Replicate_Ignore_DB:Replicate_Do_Table:Replicate_Ignore_Table:Replicate_Wild_Do_Table:Replicate_Wild_Ignore_Table:Last_Errno: 0Last_Error:Skip_Counter: 0Exec_Master_Log_Pos: 417Relay_Log_Space: 884Until_Condition: NoneUntil_Log_File:Until_Log_Pos: 0Master_SSL_Allowed: NoMaster_SSL_CA_File:Master_SSL_CA_Path:Master_SSL_Cert:Master_SSL_Cipher:Master_SSL_Key:Seconds_Behind_Master: 0Master_SSL_Verify_Server_Cert: NoLast_IO_Errno: 0Last_IO_Error:Last_SQL_Errno: 0Last_SQL_Error:Replicate_Ignore_Server_Ids:Master_Server_Id: 3301Master_UUID: a97983fc-5a29-11e6-9d28-000c29d4dc3fMaster_Info_File: /home/mysql/I3302/master.infoSQL_Delay: 0SQL_Remaining_Delay: NULLSlave_SQL_Running_State: Slave has read all relay log; waiting for more updatesMaster_Retry_Count: 86400Master_Bind:Last_IO_Error_Timestamp:Last_SQL_Error_Timestamp:Master_SSL_Crl:Master_SSL_Crlpath:Retrieved_Gtid_Set:Executed_Gtid_Set:Auto_Position: 0Replicate_Rewrite_DB:Channel_Name:Master_TLS_Version:row in set (0.00 sec) [zejin] 3302>select * from t_users;+----+------+| id | name |+----+------+| 1 | hao || 2 | zhou |+----+------+rows in set (0.00 sec) | 
如下為在線變更的具體的操作步驟:
前提:
1.要求所有的mysql版本5.7.6或更高的版本。
2.目前拓撲結構中所有的mysql的gtid_mode的值為off狀態。
3.如下的操作步驟都是有序的,不要跳躍著進行。
補充一下全局系統變量GTID_MODE變量值說明:
OFF 新事務是非GTID, Slave只接受不帶GTID的事務,傳送來GTID的事務會報錯
OFF_PERMISSIVE 新事務是非GTID, Slave即接受不帶GTID的事務也接受帶GTID的事務
ON_PERMISSIVE 新事務是GTID, Slave即接受不帶GTID的事務也接受帶GTID的事務
ON 新事務是GTID, Slave只接受帶GTID的事務
需要注意的是,這幾個值的改變是有順序的,即
off<--->OFF_PERMISSIVE<--->ON_PERMISSIVE<--->ON
新聞熱點
疑難解答