mysql主从复制中的1032错误

人工智能与算法增长营销流媒体协议

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

问题

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

主库上

  1. mysql -uroot -p
  2. show master status \G;

picture.image

主库上只看master哦

从库上

  1. mysql -uroot -p
  2. show slave status \G;

picture.image

从库上只看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. 
4. `mysql> stop slave;`
5. `Query OK, 0 rows affected (0.02 sec)`
6. 
7. `mysql> start slave;`
8. `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. 
4. `[root@test13 ~]# find / -name bin.000094`
5. `/work1/data/mysql/bin.000094`


    

2. 解析binlog

picture.image


      
 
 
  `[`
 
 
 


      1. 


    

可以看到是一条更新语句,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. 
4. `mysql> start slave;`
5. `Query OK, 0 rows affected (0.00 sec)`
6. 
7. `mysql> show slave status \G;`
8. `*************************** 1. row ***************************`
9. `Slave_IO_State: Waiting for master to send event`
10. `Master_Host: 192.168.1.163`
11. `Master_User: test123`
12. `Master_Port: 3306`
13. `Connect_Retry: 60`
14. `Master_Log_File: bin.000094`
15. `Read_Master_Log_Pos: 537124219`
16. `Relay_Log_File: mysql-relay-bin.000006`
17. `Relay_Log_Pos: 314`
18. `Relay_Master_Log_File: bin.000094`
19. `Slave_IO_Running: Yes`
20. `Slave_SQL_Running: Yes`
21. `Replicate_Do_DB:`
22. `Replicate_Ignore_DB:`
23. `Replicate_Do_Table:`
24. `Replicate_Ignore_Table:`
25. `Replicate_Wild_Do_Table:`
26. `Replicate_Wild_Ignore_Table:`
27. `Last_Errno: 0`
28. `Last_Error:`
29. `Skip_Counter: 0`
30. `Exec_Master_Log_Pos: 537124219`
31. `Relay_Log_Space: 3895`
32. `Until_Condition: None`
33. `Until_Log_File:`
34. `Until_Log_Pos: 0`
35. `Master_SSL_Allowed: No`
36. `Master_SSL_CA_File:`
37. `Master_SSL_CA_Path:`
38. `Master_SSL_Cert:`
39. `Master_SSL_Cipher:`
40. `Master_SSL_Key:`
41. `Seconds_Behind_Master: 0`
42. `Master_SSL_Verify_Server_Cert: No`
43. `Last_IO_Errno: 0`
44. `Last_IO_Error:`
45. `Last_SQL_Errno: 0`
46. `Last_SQL_Error:`
47. `Replicate_Ignore_Server_Ids:`
48. `Master_Server_Id: 163`
49. `Master_UUID: ec5e1ee1-f6e2-11e8-949d-005033ee2217`
50. `Master_Info_File: /work1/data/mysql/master.info`
51. `SQL_Delay: 0`
52. `SQL_Remaining_Delay: NULL`
53. `Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates`
54. `Master_Retry_Count: 86400`
55. `Master_Bind:`
56. `Last_IO_Error_Timestamp:`
57. `Last_SQL_Error_Timestamp:`
58. `Master_SSL_Crl:`
59. `Master_SSL_Crlpath:`
60. `Retrieved_Gtid_Set:`
61. `Executed_Gtid_Set:`
62. `Auto_Position: 0`
63. `Replicate_Rewrite_DB:`
64. `Channel_Name:`
65. `Master_TLS_Version:`
66. `1 row in set (0.00 sec)`


    

问题解决。

0
0
0
0
关于作者
关于作者

文章

0

获赞

0

收藏

0

相关资源
字节跳动 GPU Scale-up 互联技术白皮书
近日,字节跳动正式发布基于以太网极致优化的 GPU Scale-up 互联技术白皮书,推出 EthLink 的创新网络方案,旨在为 AI 集群提供低延迟、高带宽的高速互联传输,满足 AI 应用对 GPU 之间高效通信的需求。这一举措标志着字节跳动在 AI 基础设施领域的突破,有望推动通用人工智能(AGI)和大语言模型(LLM)的进一步发展。
相关产品
评论
未登录
看完啦,登录分享一下感受吧~
暂无评论