暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

mysql主从复制中的1032错误

开发架构二三事 2019-08-27
2206

1032错误----现在生产库中好多数据,在从库误删了,生产库更新后找不到了,现在主从不同步了,再跳过错误也没用,因为没这条,再更新还会报错

问题

出现了主从不一致,开始分析原因。

主库上

  1. mysql -uroot -p

  2. show master status \G; 

主库上只看master哦

从库上

  1. mysql -uroot -p

  2. show slave status \G; 

从库上只看slave哦

可以看到最近一条报错信息如下:

  1. Could not execute Update_rows event on table infosys_login.business_login_user_auth_info;

  2. Can't find record in 'business_login_user_auth_info', Error_code: 1032;

  3. handler error HA_ERR_KEY_NOT_FOUND; the event's master log bin.000094, end_log_pos 537072939

问题分析

1032主要有两种情况:

  1. 该异常时由于mysql slave备机不存在该记录,但是主机master删除时无需报1032错误,可以通过my.cnf可配置slave-skip-errors=1032 从而跳过日志中1032 ERROR报错。或者如下执行:

  1. mysql> set global sql_slave_skip_counter=1;

  2. Query OK, 0 rows affected (0.00 sec)


  3. mysql> stop slave;

  4. Query OK, 0 rows affected (0.02 sec)


  5. mysql> start slave;

  6. Query OK, 0 rows affected (0.00 sec)

  1. 上面的解决方式一般解决不了问题或无法永久解决问题时可以采取这种方式: 根据报错信息中的binlog日志文件bin.000094和endlogpos位置537072939来分析binlog,查找实际引发问题的sql。

1. 查找位置

  1. [root@test13 mysql]# find / -name mysqlbinlog

  2. /usr/bin/mysqlbinlog


  3. [root@test13 ~]# find / -name bin.000094

  4. /work1/data/mysql/bin.000094

2. 解析binlog

[


可以看到是一条更新语句,UPDATE infosys_login
. business_login_user_auth_info
where XXX ... @1=272998577393905664对应的是库中的id,去从库中查看时,这条记录确实是被开发人员手动删除了的,从而造成了1032错误。

在从库中插入这条记录,执行:

  1. insert into `business_login_user_auth_info`(`id`,`login_id`,`login_pwd`,`user_type`,`face_path`,`status`,`nick_name`,`sex`,`birthday`,`province`,`city`,`app_auth_key`,`last_login_app_type`,`last_view_time`,`last_login_ip`,`Last_login_client_id`,`create_time`,`update_time`,`h5_open_id`) values (272998577393905664,'UID_AD6EF34FE8083DC3315BE6F6D4F7A8D2','b803231ec56cebd83825b18461e20c7d',11,'http://thirdqq.qlogo.cn/g?b=oidb&k=1HPyicJeGDGXbzrHSZorTmw&s=100&t=1556471196',1,'滑翔的风v愚',1,NULL,NULL,NULL,'1',NULL,NULL,NULL,NULL,'2019-08-26 14:39:06',NULL,NULL)

再执行:

  1. mysql> stop slave;

  2. Query OK, 0 rows affected (0.00 sec)


  3. mysql> start slave;

  4. Query OK, 0 rows affected (0.00 sec)


  5. mysql> show slave status \G;

  6. *************************** 1. row ***************************

  7. Slave_IO_State: Waiting for master to send event

  8. Master_Host: 192.168.1.163

  9. Master_User: test123

  10. Master_Port: 3306

  11. Connect_Retry: 60

  12. Master_Log_File: bin.000094

  13. Read_Master_Log_Pos: 537124219

  14. Relay_Log_File: mysql-relay-bin.000006

  15. Relay_Log_Pos: 314

  16. Relay_Master_Log_File: bin.000094

  17. Slave_IO_Running: Yes

  18. Slave_SQL_Running: Yes

  19. Replicate_Do_DB:

  20. Replicate_Ignore_DB:

  21. Replicate_Do_Table:

  22. Replicate_Ignore_Table:

  23. Replicate_Wild_Do_Table:

  24. Replicate_Wild_Ignore_Table:

  25. Last_Errno: 0

  26. Last_Error:

  27. Skip_Counter: 0

  28. Exec_Master_Log_Pos: 537124219

  29. Relay_Log_Space: 3895

  30. Until_Condition: None

  31. Until_Log_File:

  32. Until_Log_Pos: 0

  33. Master_SSL_Allowed: No

  34. Master_SSL_CA_File:

  35. Master_SSL_CA_Path:

  36. Master_SSL_Cert:

  37. Master_SSL_Cipher:

  38. Master_SSL_Key:

  39. Seconds_Behind_Master: 0

  40. Master_SSL_Verify_Server_Cert: No

  41. Last_IO_Errno: 0

  42. Last_IO_Error:

  43. Last_SQL_Errno: 0

  44. Last_SQL_Error:

  45. Replicate_Ignore_Server_Ids:

  46. Master_Server_Id: 163

  47. Master_UUID: ec5e1ee1-f6e2-11e8-949d-005033ee2217

  48. Master_Info_File: /work1/data/mysql/master.info

  49. SQL_Delay: 0

  50. SQL_Remaining_Delay: NULL

  51. Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates

  52. Master_Retry_Count: 86400

  53. Master_Bind:

  54. Last_IO_Error_Timestamp:

  55. Last_SQL_Error_Timestamp:

  56. Master_SSL_Crl:

  57. Master_SSL_Crlpath:

  58. Retrieved_Gtid_Set:

  59. Executed_Gtid_Set:

  60. Auto_Position: 0

  61. Replicate_Rewrite_DB:

  62. Channel_Name:

  63. Master_TLS_Version:

  64. 1 row in set (0.00 sec)

问题解决。


文章转载自开发架构二三事,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论