主從機器關機一段時間後,先啟動了主庫(因為設定了expire_logs_days引數,啟動後就會自動刪除過期的binlog),啟動從庫後,發現從庫報如下錯誤,找不到主庫的binlog了
Last_IO_Error: Got fatal error 1236 from master when reading data from binary log: 'Could not find first log file name in binary log index file'
一種方法是重新部署主從(主庫已經有業務資料寫入),另一種方法是:主庫業務沒有業務資料寫入,可以嘗試使用如下方式:
/home/middle/mysql57/bin/mysql -h localhost -uroot -P13306 -p
mysql> stop slave;
mysql> reset slave;
mysql> reset master;
主庫獲取gtid
mysql> show master status \G;
*************************** 1. row ***************************
File: binlog.033206
Position: 154
Binlog_Do_DB:
Binlog_Ignore_DB:
Executed_Gtid_Set: 20c37c3a-a2aa-11eb-9a6b-fa163e89c1d3:1-62580571
1 row in set (0.00 sec)
mysql> set global gtid_purged='20c37c3a-a2aa-11eb-9a6b-fa163e89c1d3:1-62580571';
這個gtid是從主庫上獲取的
mysql>change master to master_host='192.168.1.100',
master_user='repuser',
master_password='123456',
master_port=13306,
master_auto_position=1;
mysql>start slave;