mysql主从同步时,由于意外的操作,可能会出现下面的错误:
Could not execute Update_rows event on table confluence.AO_92296B_AORECENTLY_VIEWED; Can’t find record in ‘AO_92296B_AORECENTLY_VIEWED’, Error_code: 1032; handler error HA_ERR_KEY_NOT_FOUND; the event’s master log mysql-bin.000101, end_log_pos 711518695
或者
Coordinator stopped because there were error(s) in the worker(s). The most recent failure being: Worker 1 failed executing transaction ‘ANONYMOUS’ at source log mysql-bin.000003, end_log_pos 1271796. See error log and/or performance_schema.replication_applier_status_by_worker table for more details about this failure or others, if any
此时需要查看end_log_pos对应的是什么数据操作,就需要把binlog二进制文件解释成可读的文件。
使用 mysqlbinlog 命令可以解释binlog文件,查询mysql数据库所有数据包括表和字段的操作记录。
binlog文件保存在mysql的data目录中。
mysqlbinlog命令保存的mysql的bin目录中。
进入mysql/bin目录,执行
./mysqlbinlog --no-defaults --base64-output=decode-rows -v /opt/mysql/data/binlog.000003 --result-file=binlog0003.sql
–no-defaults 参数是为了避免出现错误:
unknown variable ‘default-character-set=utf8mb4’
-v 参数可以解释出具体的sql:
SET TIMESTAMP=1706720159/*!*/;
BEGIN
/*!*/;
# at 777
#240201 0:55:59 server id 83 end_log_pos 858 CRC32 0x39a9a35f Table_map: `scheduler`.`QRTZ_SCHEDULER_STATE` mapped to number 100
# has_generated_invisible_primary_key=0
# at 858
#240201 0:55:59 server id 83 end_log_pos 1044 CRC32 0xb3d174b6 Update_rows: table id 100 flags: STMT_END_F
### UPDATE `scheduler`.`QRTZ_SCHEDULER_STATE`
### WHERE
### @1='quartz-scheduler'
### @2='scheduler-b76dd4d4b-46vmr1705301677479'
### @3=1706720151596
### @4=7500
### SET
### @1='quartz-scheduler'
### @2='scheduler-b76dd4d4b-46vmr1705301677479'
### @3=1706720159100
### @4=7500
# at 1044
#240201 0:55:59 server id 83 end_log_pos 1075 CRC32 0x108ff46c Xid = 226
COMMIT/*!*/;
找到错误信息里对应的end_log_pos,即可找到具体的sql。