Home > Back-end >  How do I find the command causing a replication error in MySQL
How do I find the command causing a replication error in MySQL

Time:05-21

I am trying to figure out what command is trying to be executed on the replication slave that is causing an error. The slave status is no help and the log file tells me it is trying to perform a delete so I am not too worried about skipping this error but I can't figure out what exactly it is trying to delete.

Here is the error.log entries...

2022-05-20T12:13:52.721940Z 7 [ERROR] [MY-010584] [Repl] Slave SQL for channel '': Worker 1 failed executing transaction 'ANONYMOUS' at master log mysql-bin.000004, end_log_pos 8759277; Could not execute Delete_rows event on table puzzleswaps_com.puzzle; Can't find record in 'puzzle', Error_code: 1032; handler error HA_ERR_KEY_NOT_FOUND; the event's master log FIRST, end_log_pos 8759277, Error_code: MY-001032
2022-05-20T12:13:52.722594Z 6 [ERROR] [MY-010586] [Repl] Error running query, slave SQL thread aborted. Fix the problem, and restart the slave SQL thread with "SLAVE START". We stopped at log 'mysql-bin.000004' 

So the error is coming from the master's binlog file mysql-bin.000004 just before position 8759277

But I am looking at the mysqlbinlog output and it makes no sense to me since it is spitting out a huge amount of hex code (maybe base 64 encoded?) but it ends like this...

CwgY2FyZHMsIGNvbGxlY3RvciwgZWFtZXMsIG1vZGVybtwFAAsxMjAwIC0gMTc5OQAAAAAAAAAA
AJmszQNHYoVftwAAAAAAAAAAAA5TaGVsbGV5IERhdmllcxNDb2xsZWN0b3IncyBFZGl0aW9uAIAA
AAABAAAABAEnxSkIAAAAAApjYWNoZV9ob21lwuoHwtpRAAAQAExha2UgQ29tbyBCcmVlemUlAGFy
dCwgbGFrZSBjb21vLCBwYXN0ZWwsIHZlbHZldCBwaWVjZXPuAgAJNjAwIC0gODk5AAAAAAAAAAAA
mazNAzdihV 3AAAAAAAAAAAADlBhdWwgSm9yZ2Vuc2VuFVZlbHZldCAtIFRvdWNoIFBpZWNlcwCA
AAAAAQAAAAQHKcUpCAAAAAAKY2FjaGVfaG9tZcTqB8LaUQAAAwBPd2wEAGJpcmRKAQAJMzAwIC0g
NTk5AAAAAAAAAAAAmazNAxxihV 3AAAAAAAAAAAAAIAAAAABAAD2Es8r
nq6GYiACAAAAowAAAO2nhQAAAJYCAAAAAAEAAgAg/////wIAeILH6wfC2lEAAB0AV2lsZCBXaGlt
c3kgLSBXb29kbGFuZCBXaGltc3kAACYCADEAAAAAAAAAAAAAAAkAAAAAAAAAAACZrOTbxwxTcGFj
ZWJveWpvbm ZrOTbxwxTcGFjZWJveWpvbm8AAAAAAAGQAQgBmazk28lihVtNU1taRg==
'/*!*/;
ROLLBACK /* added by mysqlbinlog */ /*!*/;
SET @@SESSION.GTID_NEXT= 'AUTOMATIC' /* added by mysqlbinlog */ /*!*/;
DELIMITER ;
# End of log file
/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;

Is there any way to see what exactly it is trying to delete?

CodePudding user response:

Here is the thing that lets say you get the above error and it says you need to check at binlog position 8759277 and file mysql-bin.000004.

mysqlbinlog --read-from-remote-server -h <ip-of-the-host> mysql-bin.000004 --verbose --base64-output=DECODE-ROWS|grep -A10 -B10 8759277

Above command will give you which command is executed on that position. once you get that you can also confirm the record on the replica. if the record is not there either you can skip the record only if there is only that statement at that position. or you can insert the record on the replica making sure you are not hitting any constraint.

  • Related