MySQL Slave Fix Relay Log Corrupted Error

MySQL Slave Fix Relay Log Corrupted Error

We have seen instances where we encounter the error like Relay log read failure: Could not parse relay log event entry on MySQL Slave.

There are number of reasons where you can encounter this problem. Most common of them is the host machine crashing or the binary log file missing or moved on the master server.

The following is the detailed error message you can find in slave status under Last_Error and/or 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.

The following is the output you can expect from SHOW SLAVE STATUS\G

mysql> SHOW SLAVE STATUS\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: db-master.gaganonthenet.com
                  Master_User: replication_user
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.0027
          Read_Master_Log_Pos: 587946175
               Relay_Log_File: mysql-relay-bin.00348
                Relay_Log_Pos: 254781654
        Relay_Master_Log_File: mysql-bin.025
             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: 2415466842
              Relay_Log_Space: 2345798498
              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)

MySQL Slave Fix Relay Log Corrupted Error

Now let’s try to fix this problem. The first thing you have to do is ensure that the binary log file is still available at the master host.

So in this case you have to look for the following two parameters which are important.

Relay_Master_Log_File: mysql-bin.025
..
..
Exec_Master_Log_Pos: 2415466842

Make sure you are noting the right values. DO NOT get confused with Master_Log_File. In some cases the two values (Relay_Master_Log_File & Master_Log_File) CAN be the same.

If the binary log file is present on the master host, then all you need to do is reset the slave to the point where replication broke.

And this can be done by executing CHANGE MASTER TO query using the values you have noted above.

The following is what you need to do.

mysql> slave stop;
Query OK, 0 rows affected (0.00 sec)
 
mysql> CHANGE MASTER TO master_log_file = 'mysql-bin.025', master_log_pos = 2415466842;
Query OK, 0 rows affected (0.02 sec)
 
mysql> start slave;
Query OK, 0 rows affected (0.00 sec)

The above should reset the slave to read the same binary log file at the position at which the replication broke.

Verify the slave status using SHOW SLAVE STATUS\G. Make sure that Exec_Master_Log_Pos is increasing and the value for Seconds_Behind_Master is decreasing. It should catch up soon.

I would highly recommend you to read the article at MySQL Performance Blog to understand the relations or importance of SHOW SLAVE STATUS\G with/to CHANGE MASTER TO.

MySQL Slave Fix Relay Log Corrupted Error

No Comments

Post a Comment

Time limit is exhausted. Please reload CAPTCHA.