MySQL复制常见错误 -- master更新一条slave不存在的记录
主从数据不一致时,master上已经有该条记录,但slave上没有这条记录,之后若在master上又更新了这条记录,此时就会报错,报错信息如下:
Last_SQL_Error: Could not execure Update_rows event on table abc.student; Can't find record in 'student', Error_code: 1032; handler error HA_ERR_KEY_NOT_FOUND; the event's master log bin-log.000006, end_log_pos 794
解决方法:在master上,用mysqlbinlog分析一下出错的binlog日志在干什么,如下所示:
mysqlbinlog --no-defaults -v -v --base64-output=DECODE-ROWS bin-log.000006 | grep -A '10' 794# at 794
#160323 17:10:36 server id 1 end_log_pos 8515214 CRC32 0x90b5f50c Update_rows: table id 151 flags: STMT_END_F
### UPDATE `abc`.`student`
### WHERE
### @1=8 /* INT meta=0 nullable=0 is_null=0 */
### @2='h' /* VARSTRING(40) meta=40 nullable=0 is_null=0 */
### @3=4 /* INT meta=0 nullable=1 is_null=0 */
### @4='failure' /* VARSTRING(40) meta=40 nullable=0 is_null=0 */
### SET
### @1=8 /* INT meta=0 nullable=0 is_null=0 */
### @2='h' /* VARSTRING(40) meta=40 nullable=0 is_null=0 */
### @3=4 /* INT meta=0 nullable=1 is_null=0 */
### @4='90' /* VARSTRING(40) meta=40 nullable=0 is_null=0 */