主从SQL线程报错处理

场景:

MySQL主从复制环境中,从库无法进行数据同步,Slave_SQL_Running: No


问题描述

在主库进行插入语句insert into 00db2.00bak21 values (10,'0021110');后,从库未查到这条数据信息,并且Slave_SQL_Running状态为No

查看从库状态,报错如下:

Last_Errno: 1396
                   Last_Error: Coordinator stopped because there were error(s) in the worker(s). The most recent failure being: Worker 1 failed executing transaction '857d06e9-a091-11ec-b901-000c29d0e59f:37' at master log 00db-binlog.000002, end_log_pos 15138. See error log and/or performance_schema.replication_applier_status_by_worker table for more details about this failure or others, if any.


原因分析:

根据 Coordinator stopped because there were error(s) in the worker(s). The most recent failure being: Worker 1 failed executing transaction '857d06e9-a091-11ec-b901-000c29d0e59f:37' at master log 00db-binlog.000002, end_log_pos 15138. See error log and/or performance_schema.replication_applier_status_by_worker table for more details about this failure or others, if any.信息查看主库二进制文件

主库操作如下:

show binlog events in '00db-binlog.000002';

信息如下:

CREATE USER '0005'@'%' IDENTIFIED WITH 'mysql_native_password' AS '*009D0D2518F4CA3282E7ACF594DE35B1CD43FC31'

---------------------------------------------------------------------------------------------

根据Last_Errno: 1396查询错误号1396

从库查询sql如下:

select LAST_ERROR_MESSAGE from performance_schema.replication_applier_status_by_worker where LAST_ERROR_NUMBER=1396;

信息如下:

Worker 1 failed executing transaction '857d06e9-a091-11ec-b901-000c29d0e59f:37' at master log 00db-binlog.000002, end_log_pos 15138; Error 'Operation CREATE USER failed for '0005'@'%'' on query. Default database: ''. Query: 'CREATE USER '0005'@'%' IDENTIFIED WITH 'mysql_native_password' AS '*009D0D2518F4CA3282E7ACF594DE35B1CD43FC31''

发现数据不同步原因是有人在从库创建用户,而在主库也从新创建了一次,从库先创建用户,而后主库又创建用户,导致事务一直过不去,直至后来在主库插入数据后,从库数据不同步。


解决方案:

手工处理使从库跳过创建用户的事务,具体操作如下:

mysql> stop slave;
Query OK, 0 rows affected (0.00 sec)

mysql> set @@session.gtid_next='857d06e9-a091-11ec-b901-000c29d0e59f:37';
Query OK, 0 rows affected (0.00 sec)

需要手工提交一下空事务

mysql>  begin;
Query OK, 0 rows affected (0.00 sec)

mysql> commit;
Query OK, 0 rows affected (0.00 sec)

再把那个session.gtid_next改回automatic

mysql> set @@session.gtid_next=automatic;
Query OK, 0 rows affected (0.00 sec)

mysql> start slave;
Query OK, 0 rows affected (0.00 sec)
mysql> show slave status \G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.16.51
                  Master_User: repuser
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: 00db-binlog.000002
          Read_Master_Log_Pos: 15832
               Relay_Log_File: 00db-relay.000013
                Relay_Log_Pos: 460
        Relay_Master_Log_File: 00db-binlog.000002
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes

跳过错误事务后  Slave_SQL_Running为Yes,主库插入的数据在从库也可以查到。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值