Bei einer Master-Slave-Replikation vom MySQL bzw. MariaDB kann es unter bestimmten Vorraussetzungen zu folgenden Fehlerbild kommen.
Die Replikation funktioniert nicht mehr, weil das entsprechenden Relay-Log-File defekt ist.
Relay log read failure
Nach der Eingabe von
mysql> SHOW SLAVE STATUS\G
Erscheint folgende Fehlermeldung:
... 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. ...
Die passiert unter anderem wenn das Slave-System unkontrolliert beendet wurde, das kann z.B. bei einem Reset des Servers der Fall sein. Das Relay-Log wird nicht vollständig auf die Platte geschrieben wie es bei einem normalen Stop des Datenbankservers der Fall gewesen wäre. Der „Datenmüll“ ist nun für unser Slave-Server nicht mehr verwertbar und eine Replikation ist somit nicht mehr möglich.
Retten können wir das System folgendermaßen.
Zuerst stoppen wir den Slave
mysql> STOP SLAVE;
und lassen wir uns nochmals alle wichtigen Informationen zum Status der Replikation ausgeben.
mysql> SHOW SLAVE STATUS\G
*************************** 1. row ***************************
Slave_IO_State:
Master_Host: x.x.x.x
Master_User: replikatoruser
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysqld-bin.006432
Read_Master_Log_Pos: 688908797
Relay_Log_File: slave-relay.004257
Relay_Log_Pos: 945811289
Relay_Master_Log_File: mysqld-bin.006430
Slave_IO_Running: No
Slave_SQL_Running: No
Replicate_Do_DB:
Replicate_Ignore_DB: information_schema
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: 945811142
Relay_Log_Space: 2752894101
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.
Replicate_Ignore_Server_Ids:
Master_Server_Id: 1
1 row in set (0.00 sec)
Wichtig sind für uns nun die Einträge Relay_Master_Log_File und Exec_Master_Log_Pos diese solle man sich genau notieren.
... Relay_Master_Log_File: mysqld-bin.006430 ... Exec_Master_Log_Pos: 945811142 ...
Nun setzen wir den Slave zurück und löschen somit alle Relay-Logs.
mysql> RESET SLAVE;
Jetzt Konfigurieren wir den Slave neu und setzten genau an der Stelle an, an der die Replikation abgebrochen wurde. Dazu benötigen wir die notierten Werte Relay_Master_Log_File und Exec_Master_Log_Pos.
mysql> CHANGE MASTER TO MASTER_LOG_FILE='Relay_Master_Log_File', MASTER_LOG_POS=Exec_Master_Log_Pos;
In unserem konkreten Fall ist das
mysql> CHANGE MASTER TO MASTER_LOG_FILE='mysqld-bin.006430', MASTER_LOG_POS=945811142;
Nach dem die Replikation wieder gestartet wurde sendet uns der Master wieder ein entsprechendes Binär-Log und die Replikation sollte wieder wie gewohnt laufen.
mysql> START SLAVE
mysql> SHOW SLAVE STATUS\G
...
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
...
Wie immer lohnt auch ein Blick in die Dokumentation von MySQL.