解決mysql開啟GTID主從同步出現1236錯誤問題
最近遇到mysql開啟gtid做復制時,從庫出現1236錯誤,導致同步無法進行,本文就這問題記錄下處理步驟,有關gtid知識在這里不做介紹,mysql版本為5.7.16。
一、錯誤原因分析
錯誤信息如下:
Last_IO_Errno: 1236
Last_IO_Error: 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.'
一般兩種情況會出現以上現象
1.在主庫上手動執行清除二進制日志文件
2.主庫重啟,重新同步時
二、解決方法:
1.在主庫上執行以下命令,查詢gtid_purged,記錄下改值
mysql> show global variables like '%gtid%'\G
2.在從庫上執行以下命令,查詢已經執行過的gtid即gtid_executed,記錄下主庫的值,本機的不需要
3.在從庫上執行以下命令停止同步線程及重置同步相關信息
mysql> stop slave;
mysql> reset slave;
mysql> reset master;
4.在從庫上設置gtid_purged
該值有兩個來源,一是在主庫上查詢的gtid_purged,二是在從庫上查詢的已經執行過的gtid_executed值(本機的就不需要,主庫上gtid)
注意:一定記得加上從庫上已經執行過的gtid,若只設置了主庫上的gtid_purged,此時從庫會重新拉取主庫上所有的二進制日志文件,同步過程會出現其他錯誤,導致同步無法進行
mysql> set @@global.gtid_purged='4fa9ab33-3077-11e6-8ee6-fcaa14d0751b:1-18240458,6e41a42e-8529-11e6-b72e-fcaa14d07546:1-56604052:56604054-56605629:56605631-56871196,9850e381-b601-11e6-8e46-fcaa14d07546:1-3126210,c5cdcae2-9cb0-11e6-909c-fcaa14d0751b:1-1189,10a59961-c02d-11e6-a2de-fcaa14d07546:1-13381418';
注意:設置gtid_purged值時,gtid_executed值必須為空否則報錯,該值清空的方法就是reset master命令
執行完,再次查看相關信息
5.重新開啟同步
mysql> change master to master_host='192.168.1.15',master_port=3306,master_user='repl',master_password='xxx',master_auto_position=1;
mysql> start slave;
當從庫追趕上主庫,此時測試主從數據是否一致,測試結果一切正常
mk-table-checksum h=192.168.1.15,u=root,p=xxx,P=3306 h=192.168.1.19,u=root,p=xxxx,P=3307 -d 6coursestudychoose_test | mk-checksum-filter




