场景

错误日志如下:

2023-05-15T11:41:06.791524+08:00 1 [ERROR] Error reading packet from server for channel '': could not find next log; the first event 'mysql-bin.001312' at 881357701, the last event read from '/data/mysql/binlog/mysql-bin.001880' at 1073780515, the last byte read from '/data/mysql/binlog/mysql-bin.001880' at 1073780515. (server_errno=1236)
2023-05-15T11:41:06.791565+08:00 1 [ERROR] Slave I/O for channel '': Got fatal error 1236 from master when reading data from binary log: 'could not find next log; the first event 'mysql-bin.001312' at 881357701, the last event read from '/data/mysql/binlog/mysql-bin.001880' at 1073780515, the last byte read from '/data/mysql/binlog/mysql-bin.001880' at 1073780515.', Error_code: 1236

原因

有同事在主库上通过手动rm mysql-bin.00xxxxvi mysql-bin.index文件的方式删除了主库的binlog文件导致的

处理方法

检查主库上mysql-bin.001880及之后的日志还存在,重新启动同步就可以恢复。 start slave

关联知识点

binlog可以在数据库中使用命令删除,会自动更新binlog的index文件,如果没有特殊情况不需要在操作系统上手动删除

删除binlog

# 删除000010以前的binlog(不包括000010)
PURGE BINARY LOGS TO 'mysql-bin.000010';
	
#删除2008-04-02 22:46:26以前的binlog	
PURGE BINARY LOGS BEFORE '2008-04-02 22:46:26';