1. 程式人生 > >啟用auto_position=1一直報錯

啟用auto_position=1一直報錯


啟用auto_position=1一直報錯 Got fatal error 1236 from master when reading data from binary log: 'The slave is connecting using CHANGE MASTER TO MASTER_AUTO_POSITION = 1, but the master has purged binary logs containing GTIDs that the slave requires.', Error_code: 1236


gtid中一些變數的理解

Retrieved_Gtid_Set: 接收到gtid集合
Executed_Gtid_Set: slave 已經執行過gtid集合,這個值使用從庫的gtid_executed 這個變數初始化
gtid_executed:執行過的gtid集合
gtid_purged:已經被purge清除掉gtid集合



--(1) 在執行start slave  的時候 ,如何計算起始的gtid值/集合



1.計算出 在從庫上執行並未清除掉的gtid集合 


在從庫已經執行的gtid集合

gtid_executed={0dd527e9-af3e-11e8-9ed6-00505683b926:1-62,0dd527e9-af3e-11e8-9ed6-00505683b927:1-3,87cf7b97-c393-11e8-845b-005056a95814:1,bb014309-e1a6-11e8-b284-00505683b926:1-12,c488995b-e256-11e8-abb7-00505683b926:1-9}


從庫上已經清除掉的gtid集合

gtid_purged={0dd527e9-af3e-11e8-9ed6-00505683b926:1-62,0dd527e9-af3e-11e8-9ed6-00505683b927:1-3,87cf7b97-c393-11e8-845b-005056a95814:1,bb014309-e1a6-11e8-b284-00505683b926:1-6:10-12}


在從庫上執行並未清除掉的gtid集合為

slave_gtids = gtid_executed - gtid_purged 

gtid_executed - gtid_purged = { c488995b-e256-11e8-abb7-00505683b926:1-9 } 

slave_gtids={ c488995b-e256-11e8-abb7-00505683b926:1-9 } 


2. 主庫傳送給從庫的第一個gtid值(也可能是一個集合)

send_first_gtids = master_gtid_executed - slave_gtids


主庫上執行的gtid集合

master_gtid_executed = { c488995b-e256-11e8-abb7-00505683b926:1-10 }


主庫傳送給從庫的第一個gtid值(也可能是一個集合)


send_first_gtids = { c488995b-e256-11e8-abb7-00505683b926:10 }



這個時候就計算出master需要傳送給slave的第一個gtid值/集合,

如果這個值已經被master purge清理掉了(也就說在master的binlog檔案中找不到了)

slave 就會報錯  1236 錯誤 


具體報錯如下 :

Got fatal error 1236 from master when reading data from binary log: 'The slave is connecting using CHANGE MASTER TO MASTER_AUTO_POSITION = 1, but the master has purged binary logs containing GTIDs that the slave requires.', Error_code: 1236



對於這種錯誤 有兩種解決方案 

1.重做slave

2.找到歷史的binlog檔案,收到從binlog檔案cp出需要的gtid集合日誌在slave執行(這裡需用到mysqlbinlog --include-gtids ),重新初始化從庫的gtid_executed 的值