GTID 全局事務標識 mysql 5.6 加入mysql
## gtid repl config need server_id=52 #開啓gtid gtid_mode=on #開啓基於gtid複製 enforce_gtid_consistency=on log-bin=mysql52-bin # slave端日誌 log-slave-updates=1 binlog_format=row # slave啓動時不會自動開啓複製 skip-slave-start=1 # choice expire_logs_days =20
(5.7.6以上能夠動態而不重啓)git
GRANT REPLICATION SLAVE,REPLICATION CLIENT ON *.* TO 'replrepl'@'10.27.%' iDENTIFIED BY 'gtidpwd' ;sql
change master to master_host='10.27.247.52',master_port=3306,master_user='replrepl',master_password='gtidpwd',master_auto_position=1;數據庫
start slave架構
#TODO ui
獲取GTIDspa
從庫設置跳過 set @@global.gtid_purged='uuid:interval[-interval]'日誌
mysql> show master status\G *************************** 1. row *************************** File: mysql52-bin.000001 Position: 467 Binlog_Do_DB: Binlog_Ignore_DB: Executed_Gtid_Set: b149ed20-eb22-11e8-9d63-005056bb87dc:1 1 row in set (0.00 sec)
mysql> show slave status\G *************************** 1. row *************************** Slave_IO_State: Master_Host: 10.27.247.52 Master_User: replrepl Master_Port: 3306 Connect_Retry: 60 Master_Log_File: Read_Master_Log_Pos: 4 Relay_Log_File: tqhtest-53-relay-bin.000001 Relay_Log_Pos: 4 Relay_Master_Log_File: 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: 0 Relay_Log_Space: 154 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: 0 Master_UUID: Master_Info_File: /var/lib/mysql/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: 0189c282-eb22-11e8-ab4b-005056bbe192:1 Auto_Position: 1 Replicate_Rewrite_DB: Channel_Name: Master_TLS_Version: 1 row in set (0.00 sec) mysql> start slave;
主庫多了 Executed_Gtid_Set: b149ed20-eb22-11e8-9d63-005056bb87dc:1code
基於gtid的replication | 基本replication |
Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates |
Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it |
主庫uuid
從庫uuid
從庫信息, 因爲沒法順利replication, exec狀態落後於retiried狀態
主庫信息
使用傳統方式報錯
mysql> set global sql_slave_skip_counter=1; |
確認數據不一樣步緣由後,進行skip操做
接受到的主庫事務號爲13,已exec的事務號是11,故跳過12先
mysql> stop slave; Query OK, 0 rows affected (0.00 sec) mysql> set GTID_NEXT='b149ed20-eb22-11e8-9d63-005056bb87dc:12'; Query OK, 0 rows affected (0.00 sec) mysql> begin;commit; Query OK, 0 rows affected (0.00 sec) Query OK, 0 rows affected (0.00 sec) mysql> set GTID_NEXT='AUTOMATIC'; Query OK, 0 rows affected (0.00 sec) mysql> start slave; Query OK, 0 rows affected (0.00 sec) mysql>
檢查slave status已經正常。
後續,確認緣由,檢查一致性。
2.1 快速切換master
stop slave
change master to master_host='10.27.247.52',master_port=3306,master_user='replrepl',master_password='gtidpwd',master_auto_position=1; start slave
因爲不須要指定logfilename與pos, 能夠快速切換,快速變動複製拓撲。基於此特性,能夠作靈活的架構。
5.7.6以前版本須要停服務
以後版本能夠動態調整。