咨询热线:4006-75-4006
售前:9:00-23:30 备案:9:00-18:00 技术:7*24h
Last_SQL_Errno: 1032(从库少数据,主库更新的时候,从库报错)
Last_SQL_Error: Could not execute Update_rows event on table test.t; Can’t find record in ‘t’, Error_code: 1032; handler error HA_ERR_KEY_NOT_FOUND; the event’s master log mysql-bin.000014, end_log_pos 1708
解决问题的办法:根据报错信息,我们可以获取到报错日志和position号,然后就能找到主库执行的哪条sql,导致的主从报错。
在主库执行:
/usr/local/mysql/bin/mysqlbinlog –no-defaults -v -v –base64-output=decode-rows /data/mysql/mysql-bin.000014 |grep -A 10 1708 > 1.log
cat 1.log
#170720 14:20:15 server id 3 end_log_pos 1708 CRC32 0x97b6bdec Update_rows: table id 113 flags: STMT_END_F ### UPDATE `test`.`t` ### WHERE ### @1=4 /* INT meta=0 nullable=0 is_null=0 */ ### @2=’dd’ /* VARSTRING(60) meta=60 nullable=1 is_null=0 */ ### SET ### @1=4 /* INT meta=0 nullable=0 is_null=0 */ ### @2=’ddd’ /* VARSTRING(60) meta=60 nullable=1 is_null=0 */ # at 1708 #170720 14:20:15 server id 3 end_log_pos 1739 CRC32 0xecaf1922 Xid = 654 COMMIT/*!*/; DELIMITER ; # End of log file ROLLBACK /* added by mysqlbinlog */; /*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/; /*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;
获取到SQL语句之后,就可以在从库反向执行SQL语句。把从库缺少的SQL语句补全,解决报错信息。
在从库依次执行:
mysql> insert into t (b) values (‘ddd’); Query OK, 1 row affected (0.01 sec) mysql> stop slave; Query OK, 0 rows affected (0.00 sec) mysql> exit Bye [root@node4 bin]# ./pt-slave-restart -uroot -proot123 2017-07-20T14:31:37 p=…,u=root node4-relay-bin.000005 283 1032