[Mysql] mysql-mha主从环境,从库报错Error_code: 1062


本文总阅读量

0、数据库版本信息:

1
5.7.22

1、从库报错信息

1
2
3
4
Last_SQL_Error: Could not execute Write_rows event on table test.tb1;
Duplicate entry '4' for key 'PRIMARY',
Error_code: 1062;
handler error HA_ERR_FOUND_DUPP_KEY; the event's master log mysql-binlog.000005, end_log_pos 273273632

2、解决方法

2.1、在主库上查询二进制文件信息:

1
/data/mysql/bin/mysqlbinlog  -v --stop-position=273273632 /data/mysql/log/mysql-binlog.000005 > /tmp/f.log

2.2、过滤出报错的pos所对应的行数:

1
cat /tmp/f.log | awk '/end_log_pos 273273632/ {print NR}'
1
22556452

2.3、根据查询到的行数,查看其上下文:

1
cat /tmp/f.log | awk 'NR==22556442,NR==22556492'

2.4、查询到insert的插入语句

1
2
3
4
5
6
7
### INSERT INTO `test`.`tb1`
### SET
### @1=4
### @2='ERC20'
### @3='GTO'
### @4=1533176390
ROLLBACK /* added by mysqlbinlog */ /*!*/;

2.5、在从库上执行下面操作,停止主从同步

1
stop slave;

2.6、删除报错提示的对应的行:

1
2
3
use test;
delete from tb1 where id=4;
select * from tb1;

2.7、重新启动主从同步,查看节点信息正常:

1
2
start slave;
show slave status\G;
目录
  1. 1. 0、数据库版本信息:
  2. 2. 1、从库报错信息
  3. 3. 2、解决方法

Proudly powered by Hexo and Theme by Lap
本站访客数人次
© 2020 zeven0707's blog