记一次MYSQL主从sql线程not_running故障处理

Posted IT那活儿

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了记一次MYSQL主从sql线程not_running故障处理相关的知识,希望对你有一定的参考价值。

 环 境:

os:redhat7,DB:mysql 6.7 主从


故障现象:

主从线程未running,同步中断


报错日志:

Could not execute Write_rows event on table skdata_2021.pj_xxxx_fpmx; Duplicate entry '043002000111-01278925' for key 'ak_key_2',

Error_code: 1062; handler error HA_ERR_FOUND_DUPP_KEY; the event's master log master-bin.000403, end_log_pos 333202176


处理步骤:

 方法一:对于数据量少的时候适用
  1. 根据唯一性key查找相关记录

  2. master库备份记录

  3. slave库删除重复记录

  方法二:对于数据量大的时候适用

1. 从库操作

show variables like '%slave_exec_mode%';

set global slave_exec_mode='IDEMPOTENT';

stop slave;

start slave;

2. 确认主从无延迟及确认数据一致 操作完后,修改回去-------可以了,改回去(存在数据不一致的风险)

set global slave_exec_mode='STRICT';

stop slave;

start slave;


UPDATE报错:

Could not execute Update_rows event on table skdata_2021.qrtz_scheduler_state; Can't find record in 'qrtz_scheduler_state',

Error_code: 1032; handler error HA_ERR_KEY_NOT_FOUND; the event's master log master-bin.000403, end_log_pos 333327330


1. 使用mysqlbinlog主库操作:

   
     
     
   

mysqlbinlog --no-defaults --base64-output=decode-rows --verbose --start-position=333326998 --stop-position=333327330 master-bin.000403
把更新前记录找出,并在从库插入执行,再启动slave sql进程
SET @@session.collation_database=DEFAULT/*!*/;
BEGIN
/*!*/;
# at 333327142
#210628 10:41:19 server id 127 end_log_pos 333327216 CRC32 0xb31a9243 Table_map: `skdata_2021`.`qrtz_scheduler_state` mapped to number 110214
# at 333327216
#210628 10:41:19 server id 127 end_log_pos 333327330 CRC32 0x85a6c09f Update_rows: table id 110214 flags: STMT_END_F
### UPDATE `skdata_2021`.`qrtz_scheduler_state`
### WHERE
### @1='fpskgl21616596076563'
### @2=1624848058505
### @3=20000
### SET
### @1='fpskgl21616596076563'
### @2=1624848078982
### @3=20000
ROLLBACK /* added by mysqlbinlog */ /*!*/;
SET @@SESSION.GTID_NEXT= 'AUTOMATIC' /* added by mysqlbinlog */ /*!*/;
DELIMITER ;
# End of log file
/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;


2. 从库insert update之前的记录
   
     
     
   

set sql_log_bin=0;

insert into `skdata_2021`.`qrtz_scheduler_state` values ('fpskgl21616596076563',1624848058505,20000);
commit;
set sql_log_bin=1;


3. 启动slave sql线程
   
     
     
   
start slave sql_thread;


END


更多精彩干货分享

点击下方名片关注

IT那活儿