MySQL 5.1主从同步Relay log read failure错误现象
众所周知,MySQL 5.1版本的Replication机制存在较多缺陷。尽管每次版本更新都会伴随大量同步相关的改进,但MySQL 5.1在性能上表现突出,因此许多用户仍选择使用该版本,同时也需频繁应对由此引发的Bug。例如,在执行show slave status\G命令时,可能观察到如下输出: 复制代码 代码如下: mysql> show slave status\G *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: 192.168.10.118 Master_User: repl_wu Master_Port: 3306 Connect_Retry: 30 Master_Log_File: mysql-bin.005121 Read_Master_Log_Pos: 64337286 Relay_Log_File: relay-bin.003995 Relay_Log_Pos: 18446697137031827760 Relay_Master_Log_File: mysql-bin.005121 Slave_IO_Running: Yes Slave_SQL_Running: No Replicate_Do_DB: Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Errno: 1594 Last_Error: Relay log read failure: Could not parse relay log event entry. The possible reasons are: the master's binary log is corrupted (you can check this by running 'mysqlbinlog' on the binary log), the slave's relay log is corrupted (you can check this by running 'mysqlbinlog' on the relay log), a network problem, or a bug in the master's or slave's MySQL code. If you want to check the master's binary log or slave's relay log, you will be able to know their names by issuing 'SHOW SLAVE STATUS' on this slave. Skip_Counter: 0 Exec_Master_Log_Pos: 4 Relay_Log_Space: 64337901 Until_Condition: None Until_Log_File: Until_Log_Pos: 0 Master_SSL_Allowed: No Master_SSL_CA_File: Master_SSL_CA_Path: Master_SSL_Cert: Master_SSL_Cipher: Master_SSL_Key: Seconds_Behind_Master: NULL Master_SSL_Verify_Server_Cert: No Last_IO_Errno: 0 Last_IO_Error: Last_SQL_Errno: 1594 Last_SQL_Error: Relay log read failure: Could not parse relay log event entry. The possible reasons are: the master's binary log is corrupted (you can check this by running 'mysqlbinlog' on the binary log), the slave's relay log is corrupted (you can check this by running 'mysqlbinlog' on the relay log), a network problem, or a bug in the master's or slave's MySQL code. If you want to check the master's binary log or slave's relay log, you will be able to know their names by issuing 'SHOW SLAVE STATUS' on this slave. 1 row in set (0.00 sec)
从上述输出信息可以看出,问题出在中继日志(Relay Log)或主库的二进制日志(Binary Log)出现了异常。
如果确定是中继日志损坏,只需找到正确的同步时间点,重新建立同步关系,从而生成新的中继日志即可解决问题。但如果主库的二进制日志损坏,处理起来则较为复杂。
根据经验判断,此类情况多由中继日志损坏引起。具体的处理方法如下:
首先需要确定当前的同步断点位置。
日志文件信息显示:Master_Log_File: mysql-bin.005121,Relay_Master_Log_File: mysql-bin.005121。应以Relay_Master_Log_File为准,Master_Log_File作为参考。
日志执行的时间点位置为: 复制代码 代码如下:Exec_Master_Log_Pos: 4
确认位置后,可执行以下操作: 复制代码 代码如下: mysql>stop slave; mysql>change master to Master_Log_File='mysql-bin.005121', Master_Log_Pos=4; mysql>start slave; mysql>show slave status\G;
执行完毕后,需再次检查状态以确认同步是否恢复正常。
针对此类问题的预防建议:
对于仍在使用MySQL-5.1.36及以下版本的用户,建议尽快升级到MySQL-5.1.40或MySQL-5.1.37sp1版本,以修复已知的同步Bug。