Last_IO_Errno: 1236
Last_IO_Error: Got fatal error 1236 from master when reading data from binary log:
'Client requested master to start replication from impossible position;
the first event 'mysql-bin.003583' at 45997491,
the last event read from './mysql-bin.003583' at 4,
the last byte read from './mysql-bin.003583' at 4.'
SHOW SLAVE STATUS\G 顯示:
Master_Log_File: mysql-bin.003583Read_Master_Log_Pos: 45997491(遠大於文件實際大小)Slave_IO_Running: Nomysql-bin.003583 文件**已損壞或被截斷**導致實際大小遠小於從庫記錄的位置。mysqlbinlog /var/lib/mysql/mysql-bin.003583 報錯 Error in Log_event::read_log_event(): 'read error',確認文件損壞。| 方案 | 適用場景 | 數據風險 | 操作複雜度 |
|---|---|---|---|
| 全量重建所有從庫 | 數據極其敏感、可接受停機窗口 | 零丟失 | 高(需鎖表/熱備份/導入) |
| 跳過損壞 Binlog,指向下一個文件 + 關鍵表同步校驗 | 業務允許短暫不一致、有 pt-table-sync 工具 | 極低(僅損壞 Binlog 區間的增量) | 中 |
| 主庫重置 Binlog(RESET MASTER)+ 全量重建 | 主庫 Binlog 大面積損壞、無從庫可用 | 零丟失(若有備份) | 高 |
STOP SLAVE;
CHANGE MASTER TO MASTER_LOG_FILE='mysql-bin.003584', MASTER_LOG_POS=4; -- 指向下一個 Binlog 文件開頭
START SLAVE;
SHOW SLAVE STATUS\G -- 確認 Slave_IO_Running: Yes, Slave_SQL_Running: Yes
SHOW BINARY LOGS; 確認 mysql-bin.003584 存在且正常。# 安裝 Percona Toolkit
apt-get install percona-toolkit # 或 yum install percona-toolkit
# 校驗指定表
pt-table-checksum h=master_ip,u=repl,p=pass --databases=db1 --tables=t1,t2
# 修復不一致
pt-table-sync --execute h=master_ip,u=repl,p=pass --databases=db1 --tables=t1,t2
MASTER_LOG_POS=4?0xfe 0x62 0x69 0x6e("fe bin"),Position 4 即為第一個事件起始位置。POS=0 或 4 效果等價,均表示從文件開頭開始讀取。sync_binlog=1、innodb_flush_log_at_trx_commit=1 保證 Binlog 與 Redo Log 持久化一致性。mysqlbinlog 校驗 Binlog 完整性:mysqlbinlog mysql-bin.000001 >/dev/null && echo OK。Error 1236 核心是**主庫 Binlog 文件損壞導致從庫請求位置越界**。最快恢復路徑:從庫跳過損壞文件指向下一個 Binlog + 關鍵表 pt-table-sync 修復。根治需夯實存儲可靠性、監控告警、GTID 架構升級與定期演練。