如何在 MySQL 中找到导致复制错误的命令

How do I find the command causing a replication error in MySQL

我试图弄清楚试图在导致错误的复制从属服务器上执行什么命令。从属状态没有帮助,日志文件告诉我它正在尝试执行删除,所以我不太担心跳过这个错误,但我无法弄清楚它到底想删除什么。

这是 error.log 个条目...

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' 

所以错误来自master的binlog文件mysql-bin.000004就在位置8759277

之前

但我正在查看 mysqlbinlog 输出,这对我来说毫无意义,因为它吐出了大量的十六进制代码(可能是 base 64 编码?)但它是这样结束的.. .

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*/;

有什么方法可以查看它到底要删除什么?

假设您遇到上述错误,它表示您需要检查 binlog 位置 8759277 和文件 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

上面的命令会给你在那个位置执行的命令。一旦你得到它,你也可以确认副本上的记录。如果记录不存在,则只有在该位置只有该语句时,您才能跳过该记录。或者您可以在副本上插入记录,确保您没有遇到任何限制。