Friday, November 20, 2015

MySQL slave relay log corrupted

9:20 PM Posted by Dilli Raj Maharjan No comments

MySQL replication stopped with slave relay log corruption. Error message will be as below.


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.

Output of SHOW SLAVE STATUS\G is as below.








































Following information is required to fix this issue. Carefully note the information. Any mistake may lead to unrecoverable state of replication.

Master_Log_File: mysql-bin.000021
Read_Master_Log_Pos: 347919174
Relay_Log_File: mysql-relay-bin.000004
Relay_Log_Pos: 16247045
Relay_Master_Log_File: mysql-bin.000021
Exec_Master_Log_Pos: 324385114

We need to verify binlog file status on master server. Execute following command to verify the binlog status. If there is any error message returned it means binlog is corrupted on master server. No error message returned means binlog file's status is fine. 

In our case there is no binlog corruption on master server. If there are any error then re-setup mysql replication slave.

mysqlbinlog mysql-bin.000021 > /tmp/mysql-bin.000021






Using same mysqlbinlog command we can verify relay-binlog file status on slave server. Execute command below to verify the status. In our case there is log corruption, so it can be easily fixed with reset slave and other commands below.

mysqlbinlog mysql-relay-bin.000004 > /tmp/mysql-relay-bin.000004






Use the command below to fix the issue. Use value of Exec_Master_Log_Pos, noted above for MASTER_LOG_POS and value of Relay_Master_Log_File for MASTER_LOG_FILE.

stop slave;
reset slave all;
show slave status\G
CHANGE MASTER TO MASTER_HOST='192.168.1.1',MASTER_USER='mysql_slave', MASTER_PASSWORD='PASSWORD', MASTER_LOG_FILE='mysql-bin.000021', MASTER_LOG_POS=324385114;
start slave;











Additionally if we need to configure delayed master then execute command below for delayed replication.

stop slave;
change master to master_delay=86400;
start slave;





0 comments:

Post a Comment