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'
表示 Slave 無法在 Master 的 binlog 索引中找到指定的起始日誌文件,常見於 Master 重啟、binlog 過期清理、或手動刪除 binlog 導致。
| 場景 | 原因 | 典型特徵 |
|---|---|---|
| binlog 過期 | expire_logs_days 到期自動清理 | Master 上 show binary logs 缺少 Slave 需要的文件 |
| 手動刪除 | 誤執行 PURGE BINARY LOGS 或 rm | binlog 索引文件與實際文件不一致 |
| Master 重啟 | 新建 binlog 文件,舊文件被清理 | Slave 還在舊文件位置 |
| 長時間斷連超過 binlog 保留窗口 | 重連時找不到同步點 |
# 1. Master 確認當前 binlog 位置
SHOW MASTER STATUS;
# File: mysql-bin.000045, Position: 123456
# 2. Master 導出全量備份
mysqldump --single-transaction --master-data=2 --all-databases > full.sql
# 3. Slave 停止同步並導入
STOP SLAVE;
mysql < full.sql
# 4. 重新配置同步點
CHANGE MASTER TO
MASTER_HOST='master_ip',
MASTER_USER='repl_user',
MASTER_PASSWORD='password',
MASTER_LOG_FILE='mysql-bin.000045',
MASTER_LOG_POS=123456;
START SLAVE;
# 查看 Master 現有最早 binlog
SHOW BINARY LOGS;
# 假設最早是 mysql-bin.000040
# Slave 跳過到最早可用位置
STOP SLAVE;
CHANGE MASTER TO MASTER_LOG_FILE='mysql-bin.000040', MASTER_LOG_POS=4;
START SLAVE;
⚠️ 風險:跳過的 binlog 內容將永久丟失,僅適用於可重放或非核心業務。
若有其他正常 Slave,可將其提升為新 Master,或從其獲取缺失 binlog 文件補齊。
expire_logs_days=7 以上,配合磁碟監控PURGE BINARY LOGS,改用自動過期Seconds_Behind_Master、Slave_IO_Running、Master binlog 磁碟佔用gtid_mode=ON),自動定位同步點,彈性容錯
# 開啟 GTID 後,無需指定文件位置
CHANGE MASTER TO
MASTER_HOST='master_ip',
MASTER_USER='repl_user',
MASTER_PASSWORD='password',
MASTER_AUTO_POSITION=1;
START SLAVE;
強烈建議生產環境遷移至 GTID 架構,徹底解決 1236 類定位問題。