3分钟解决MySQL 1032主从错误

Part1:写在最前

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

解决方案

Part1:临时方案

mysql> stop slave;

Query OK, 0 rows

affected (0.00 sec)

mysql> set global sql_slave_skip_counter=1;

Query OK, 0 rows

affected (0.00 sec)

mysql> start slave;

Query OK, 0 rows

affected (0.00 sec)

Part2:永久方案

end_log_pos 有了它,根据pos值,直接就能找到,找到delete那条数据,反做(变成insert)

故障模拟

HE1从库误删

mysql> delete from helei where id=3;

Query OK, 1 row

affected (0.29 sec)

mysql> select * from helei;

+----+------+

| id | text |

+----+------+

| 1 | aa

|

| 2 | bb

|

| 4 | ee

|

| 5 | ff

|

| 6 | gg

|

| 7 | hh

|

+----+------+

6 rows in set (0.00

sec)

mysql> show slave status\G;

***************************

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

Slave_IO_State: Waiting for

master to send event

Master_Host: 192.168.1.250

Master_User: mysync

Master_Port: 2503306

Connect_Retry: 60

Master_Log_File: mysql-bin.000005

Read_Master_Log_Pos: 3711

Relay_Log_File:

HE1-relay-bin.000007

Relay_Log_Pos: 484

Relay_Master_Log_File: mysql-bin.000005

Slave_IO_Running: Yes

Slave_SQL_Running: Yes

此时从库状态是正常的,但一旦主库对该条记录进行操作

HE3主库更新从库刚刚误删的数据

mysql> update helei set text='ccc' where id=3;

Query OK, 1 row

affected (0.01 sec)

Rows matched: 1 Changed: 1

Warnings: 0

mysql> select * from helei;

+----+------+

| id | text |

+----+------+

| 1 | aa

|

| 2 | bb

|

| 3 | ccc

|

| 4 | ee

|

| 5 | ff

|

| 6 | gg

|

| 7 | hh

|

+----+------+

7 rows in set (0.00

sec)

HE1从库报错

mysql> show slave status\G;

***************************

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

Slave_IO_State: Waiting for

master to send event

Master_Host: 192.168.1.250

Master_User: mysync

Master_Port: 2503306

Connect_Retry: 60

Master_Log_File: mysql-bin.000005

Read_Master_Log_Pos: 3918

Relay_Log_File:

HE1-relay-bin.000007

Relay_Log_Pos: 484

Relay_Master_Log_File: mysql-bin.000005

Slave_IO_Running: Yes

Slave_SQL_Running: No

Replicate_Do_DB:

Replicate_Ignore_DB:

Replicate_Do_Table:

Replicate_Ignore_Table:

Replicate_Wild_Do_Table:

Replicate_Wild_Ignore_Table:

Last_Errno: 1032

Last_Error: Could not

execute Update_rows event on table test.helei; Can't find record in 'helei',

Error_code: 1032; handler error HA_ERR_KEY_NOT_FOUND; the event's master log

mysql-bin.000005, end_log_pos 3887

Skip_Counter: 0

Exec_Master_Log_Pos: 3711

Relay_Log_Space: 1626

Until_Condition: None

Until_Log_File:

Until_Log_Pos: 0

Master_SSL_Allowed: No

Master_SSL_CA_File:

Master_SSL_CA_Path:

Master_SSL_Cert:

Master_SSL_Cipher:

Master_SSL_Key:

Seconds_Behind_Master: NULL

Master_SSL_Verify_Server_Cert:

No

Last_IO_Errno: 0

Last_IO_Error:

Last_SQL_Errno: 1032

Last_SQL_Error: Could not execute Update_rows event on table test.helei;

Can't find record in 'helei', Error_code: 1032; handler error

HA_ERR_KEY_NOT_FOUND; the event's master log mysql-bin.000005, end_log_pos 3887(这个mysql-bin.000005,end_log_pos

3887是主库的)

Replicate_Ignore_Server_Ids:

Master_Server_Id: 2503306

Master_UUID:

f7c96432-f665-11e5-943f-000c2967a454

Master_Info_File:

/data/mysql/master.info

SQL_Delay: 0

SQL_Remaining_Delay: NULL

Slave_SQL_Running_State:

Master_Retry_Count: 86400

Master_Bind:

Last_IO_Error_Timestamp:

Last_SQL_Error_Timestamp: 160331 09:25:02

Master_SSL_Crl:

Master_SSL_Crlpath:

Retrieved_Gtid_Set:

Executed_Gtid_Set:

Auto_Position: 0

1 row in set (0.00

sec)

此时主从又不同步了,如果还去执行跳过错误操作,主从恢复同步,而且状态均为yes,但!这并不能解决该问题,如果主库又更新该条记录,那么还是会报相同错误,而且pos号还会变,这就导致了恢复时你不知道前一条的pos号,导致丢失数据。

mysql> stop slave;

Query OK, 0 rows

affected (0.00 sec)

mysql> set global sql_slave_skip_counter=1;

Query OK, 0 rows

affected (0.00 sec)

mysql> start slave;

Query OK, 0 rows

affected (0.00 sec)

mysql> select * from helei;

+----+--------+

| id | text |

+----+--------+

| 1 | aa

|

| 2 | bb

|

| 4 | ee

|

| 5 | ff

|

| 6 | gg

|

| 7 | hh

|

| 8 | helei1 |

+----+--------+

7 rows in set (0.00 sec)

mysql> show slave status\G;

***************************

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

Slave_IO_State: Waiting for

master to send event

Master_Host: 192.168.1.250

Master_User: mysync

Master_Port: 2503306

Connect_Retry: 60

Master_Log_File: mysql-bin.000005

Read_Master_Log_Pos: 4119

Relay_Log_File:

HE1-relay-bin.000008

Relay_Log_Pos: 283

Relay_Master_Log_File: mysql-bin.000005

Slave_IO_Running: Yes

Slave_SQL_Running: Yes

这里虽然通过跳过错误达到恢复主从同步,但如果主库又对该条记录更新

mysql> update helei set text='cccc' where id=3;

Query OK, 1 row

affected (0.00 sec)

mysql> show slave status\G;

***************************

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

Slave_IO_State: Waiting for

master to send event

Master_Host: 192.168.1.250

Master_User: mysync

Master_Port: 2503306

Connect_Retry: 60

Master_Log_File: mysql-bin.000005

Read_Master_Log_Pos: 4328

Relay_Log_File:

HE1-relay-bin.000008

Relay_Log_Pos: 283

Relay_Master_Log_File: mysql-bin.000005

Slave_IO_Running: Yes

Slave_SQL_Running: No

Replicate_Do_DB:

Replicate_Ignore_DB:

Replicate_Do_Table:

Replicate_Ignore_Table:

Replicate_Wild_Do_Table:

Replicate_Wild_Ignore_Table:

Last_Errno: 1032

Last_Error: Could not execute Update_rows event on table test.helei;

Can't find record in 'helei', Error_code: 1032; handler error

HA_ERR_KEY_NOT_FOUND; the event's master log mysql-bin.000005, end_log_pos 4297

Skip_Counter: 0

Exec_Master_Log_Pos: 4119

Relay_Log_Space: 1435

Until_Condition: None

Until_Log_File:

Until_Log_Pos: 0

Master_SSL_Allowed: No

Master_SSL_CA_File:

Master_SSL_CA_Path:

Master_SSL_Cert:

Master_SSL_Cipher:

Master_SSL_Key:

Seconds_Behind_Master: NULL

Master_SSL_Verify_Server_Cert:

No

Last_IO_Errno: 0

Last_IO_Error:

Last_SQL_Errno: 1032

Last_SQL_Error: Could not execute Update_rows event on table test.helei;

Can't find record in 'helei', Error_code: 1032; handler error

HA_ERR_KEY_NOT_FOUND; the event's master log mysql-bin.000005, end_log_pos 4297

Replicate_Ignore_Server_Ids:

Master_Server_Id: 2503306

Master_UUID:

f7c96432-f665-11e5-943f-000c2967a454

Master_Info_File:

/data/mysql/master.info

SQL_Delay: 0

SQL_Remaining_Delay: NULL

Slave_SQL_Running_State:

Master_Retry_Count: 86400

Master_Bind:

Last_IO_Error_Timestamp:

Last_SQL_Error_Timestamp: 160331 09:33:34

Master_SSL_Crl:

Master_SSL_Crlpath:

Retrieved_Gtid_Set:

Executed_Gtid_Set:

Auto_Position: 0

如何快速解决MySQL 1032 主从错误

mysql 1032错误_如何快速解决MySQL 1032 主从错误相关推荐

  1. mysql内部时区_一文解决MySQL时区相关问题

    前言: 在使用MySQL的过程中,你可能会遇到时区相关问题,比如说时间显示错误.时区不是东八区.程序取得的时间和数据库存储的时间不一致等等问题.其实,这些问题都与数据库时区设置有关,本篇文章将从数据库 ...

  2. mysql导入数据表越来越慢,快速解决mysql导数据时,格式不对、导入慢、丢数据的问题...

    快速解决mysql导数据时,格式不对.导入慢.丢数据的问题 如果希望一劳永逸的解决慢的问题,不妨把你的mysql升级到mysql8.0吧,mysql8.0默认的字符集已经从latin1改为utf8mb ...

  3. mysql查询出现毫秒值快速解决方法

    mysql查询出现毫秒值快速解决方法 出现了这个问题,你就去看一你的dto和数据库里面的格式是否是对照的,如果你数据库里面保存时间的格式是datetime,那么dto的接收类型应该是Date,但是这种 ...

  4. 使用MySQL自带工具mysqlhotcopy快速备份mysql数据库

    使用MySQL自带工具mysqlhotcopy快速备份mysql数据库 发表于82 天前 ⁄ 网站备份 ⁄ 暂无评论 mysqlhotcopy是一个Perl脚本,最初由Tim Bunce编写并提供.它 ...

  5. 计算机开机总显示密码错误如何解决,快速解决win10开机密码错误开不了机的问题...

    快速解决win10开机密码错误开不了机的问题 导语:win10开机密码总是显示错误,怎么快速解决这个问题呢?下面是小编为你整理的快速解决win10开机密码错误开不了机的问题,希望对你有帮助! 方法/步 ...

  6. mysql怎么定位错误信息_如何快速定位MySQL 的错误日志(Error Log)?

    日志文件是MySQL数据库的重要组成部分,包括有6种不同的日志文件: 错误日志: -log-err 查询日志: -log 慢查询日志: -log-slow-queries 更新日志: -log-upd ...

  7. 如何批量删除mysql的数据库_如何快速批量删除Mysql数据库中的数据表

    一个mysql数据库中,是可以同时安装几个网站程序的,在使用中,我们只需要用不同的数据库表前缀来区分就可以了.但随着我们不断调试,那么数据 库中的表,就会一天天的多起来,如一个一个的删除就很麻烦.很辛 ...

  8. mysql隐藏用户名_系统默认的MySQL用户名消失的解决方法(修正版)

    修改MySQL下的默认mysql数据库的user表,删除所有host为localhost记录,另 外添加一些其他记录,重新启动MySQL服务器.执行show databases,只出现informat ...

  9. 修改mysql数据库名方法_安全快速修改Mysql数据库名的5种方法

    1. RENAME DATABASE db_name TO new_db_name 这个..这个语法在mysql 5.1.7中被添加进来,到了5.1.23又去掉了. 据说有可能丢失数据.还是不要用的好 ...

最新文章

  1. MAP 最大后验——利用经验数据获得对未观测量的点态估计
  2. Asp.net Mvc Codeplex Preview 5 第三篇 实现Action参数传递繁杂类型 【转】
  3. 10分钟教你看懂mongodb的npm包
  4. 7、Java Swing JTextArea:文本域组件。 JScrollPane:滚动窗口
  5. Kubuntu中thunderbird最小化到任务栏
  6. 缓存应用--Memcached分布式缓存简介(二)
  7. 台式linux桌面远程链接华为云windows服务器桌面
  8. Vector Math for 3D Computer Graphics (Bradley Kjell 著)
  9. SpringMVC文件上传(二)指定文件
  10. 微型计算机中call指令,微机原理 第四章 微型计算机指令系统.ppt
  11. 笔记本怎么自己装系统?u盘装系统windows7教程图解
  12. 设置linux定时任务,linux定时任务的设置
  13. 深入了解ElasticSearch的Nested数据类型
  14. 167. 两数之和 II - 输入有序数组633. 平方数之和
  15. uva 10859 放置街灯--Placing Lampposts
  16. 什么是overlay?如何定制overlay?
  17. 海思Hi3519A开发(6.sample内容介绍)
  18. 纠结建模的话,手绘3D建模提高你的模型制作能力和美术绘制能力
  19. Spring连接Mysql数据库
  20. VS2015无法打开输入文件xxx.lib

热门文章

  1. 复变函数-复指数形式
  2. 最近研究NFC的总结
  3. 雷锋网巴展见闻录:5G 手机也许会迟到,但不会缺席 | MWC 2019...
  4. 鼠标图标怎么自定义_苹果ios14怎么自定义图标 图标位置自由排列换风格教程
  5. 使用math.sin时报错only size-1 arrays can be converted to Python scalar
  6. 【求职】作业帮 Java 方向面经
  7. Mysql占用CPU过高排查过程及可能优化方案
  8. java 307跳转_GitHub - yy307/java-weixinlib: 微信公众平台接入
  9. 创建新的domian域
  10. 一个屌丝程序员的青春(三三)