mysql主从误重复创建用户报错1396处理[通俗易懂]

mysql主从误重复创建用户报错1396处理[通俗易懂]在mysql主从或者mysql分布式架构,某些时候主从中断报错1396,经分析发现重复创建用户导致。如何处理呢?

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺

mysql主从误重复创建用户报错1396处理

问题:
在mysql主从或者mysql分布式架构某些时候主从中断,经分析发现重复创建用户导致。

场景一、
如在日常的维护中,在主从架构或者分布式的架构中,要创建某些维护用户。比如创建运维用户,这个应该主库创建用户即可,同时主从库针对此用户设置免密登录。但是管理员同学不小心在主库从库同时执行了创建用户语句。

场景二、
如上线前中在分布式架构一主多从多分片部署运维用户,创建用户在主节点上执行,但是另外一部分同学不知道,正好做了同城切换测试,结果也出现了恰巧出现了重建用户情况。

如何处理:
此种情况是特殊情况,下面以传统主从模拟此报错和处理步骤。

初始化主从:
主库
mysql> show slave hosts
±———–±————-±—–±———–±————————————-+
| Server_id | Host | Port | Master_id | Slave_UUID |
±———–±————-±—–±———–±————————————-+
| 2624197123 | xx.x.xxx.xx6 | 3819 | 2624198899 | 4677ee4c-1404-11ea-80dd-00505699b577 |
±———–±————-±—–±———–±————————————-+

mysql> show master status \G;
*************************** 1. row ***************************
File: mysql-bin.000001
Position: 154
Binlog_Do_DB:
Binlog_Ignore_DB:
Executed_Gtid_Set:

从库

mysql> show slave status \G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: testdb11
Master_User: repusr
Master_Port: 3819
Connect_Retry: 60
Master_Log_File: mysql-bin.000001
Read_Master_Log_Pos: 154
Relay_Log_File: relay-bin.000002
Relay_Log_Pos: 367
Relay_Master_Log_File: mysql-bin.000001
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 154
Relay_Log_Space: 568
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: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 2624198899
Master_UUID: 845133e9-1404-11ea-a37b-005056991dcd
Master_Info_File: /mysqldata/mysql/data/data/master.info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 1
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
1 row in set (0.00 sec)

ERROR:
No query specified

mysql> show master status \G;
*************************** 1. row ***************************
File: mysql-bin.000001
Position: 154
Binlog_Do_DB:
Binlog_Ignore_DB:
Executed_Gtid_Set:
1 row in set (0.00 sec)

ERROR:
No query specified

主库
create table mysql(id int);
create table mysq2(id int);
create table mysq3(id int);

mysql> show master status \G;
*************************** 1. row ***************************
File: mysql-bin.000001
Position: 672
Binlog_Do_DB:
Binlog_Ignore_DB:
Executed_Gtid_Set: 845133e9-1404-11ea-a37b-005056991dcd:1-3
1 row in set (0.00 sec)

从库

mysql> show slave status \G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: testdb1
Master_User: repusr
Master_Port: 3819
Connect_Retry: 60
Master_Log_File: mysql-bin.000001
Read_Master_Log_Pos: 672
Relay_Log_File: relay-bin.000002
Relay_Log_Pos: 885
Relay_Master_Log_File: mysql-bin.000001
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 672
Relay_Log_Space: 1086
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: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 2624198899
Master_UUID: 845133e9-1404-11ea-a37b-005056991dcd
Master_Info_File: /mysqldata/mysql/data/data/master.info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set: 845133e9-1404-11ea-a37b-005056991dcd:1-3
Executed_Gtid_Set: 845133e9-1404-11ea-a37b-005056991dcd:1-3
Auto_Position: 1
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:

主库同时创建相同用户:
从库创建会话:
mysql> create user testing@’%’;
Query OK, 0 rows affected (0.01 sec)

mysql> show master status \G;
*************************** 1. row ***************************
File: mysql-bin.000001
Position: 365
Binlog_Do_DB:
Binlog_Ignore_DB:
Executed_Gtid_Set: 4677ee4c-1404-11ea-80dd-00505699b577:1,
845133e9-1404-11ea-a37b-005056991dcd:1-3

主库创建会话:
mysql> create user testing@’%’;
Query OK, 0 rows affected (0.00 sec)

mysql> show global variables like ‘%gtid%’;
±———————————±——————————————+
| Variable_name | Value |
±———————————±——————————————+
| binlog_gtid_simple_recovery | ON |
| enforce_gtid_consistency | ON |
| gtid_executed | 845133e9-1404-11ea-a37b-005056991dcd:1-4 |
| gtid_executed_compression_period | 1000 |

然后从库报错:
mysql> show slave status \G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: testdb1
Master_User: repusr
Master_Port: 3819
Connect_Retry: 60
Master_Log_File: mysql-bin.000001
Read_Master_Log_Pos: 883
Relay_Log_File: relay-bin.000002
Relay_Log_Pos: 885
Relay_Master_Log_File: mysql-bin.000001
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: 1396
Last_Error: Coordinator stopped because there were error(s) in the worker(s). The most recent failure being: Worker 0 failed executing transaction ‘845133e9-1404-11ea-a37b-005056991dcd:4’ at master log mysql-bin.000001, end_log_pos 883. See error log and/or performance_schema.replication_applier_status_by_worker table for more details about this failure or others, if any.
Skip_Counter: 0
Exec_Master_Log_Pos: 672
Relay_Log_Space: 1297
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: 1396
Last_SQL_Error: Coordinator stopped because there were error(s) in the worker(s). The most recent failure being: Worker 0 failed executing transaction ‘845133e9-1404-11ea-a37b-005056991dcd:4’ at master log mysql-bin.000001, end_log_pos 883. See error log and/or performance_schema.replication_applier_status_by_worker table for more details about this failure or others, if any.
Replicate_Ignore_Server_Ids:
Master_Server_Id: 2624198899
Master_UUID: 845133e9-1404-11ea-a37b-005056991dcd
Master_Info_File: /mysqldata/mysql/data/data/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: 191225 20:15:51
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set: 845133e9-1404-11ea-a37b-005056991dcd:1-4
Executed_Gtid_Set: 4677ee4c-1404-11ea-80dd-00505699b577:1,
845133e9-1404-11ea-a37b-005056991dcd:1-3
Auto_Position: 1
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
1 row in set (0.00 sec)

ERROR:
No query specified

从库查询gtid
mysql> show global variables like ‘%gtid%’;
±———————————±———————————————————————————+
| Variable_name | Value |
±———————————±———————————————————————————+
| binlog_gtid_simple_recovery | ON |
| enforce_gtid_consistency | ON |
| gtid_executed | 4677ee4c-1404-11ea-80dd-00505699b577:1,
845133e9-1404-11ea-a37b-005056991dcd:1-3 |
| gtid_executed_compression_period | 1000 |
| gtid_mode | ON |
| gtid_owned | |
| gtid_purged | 845133e9-1404-11ea-a37b-005056991dcd:1-3 |
| session_track_gtids | OFF |
±———————————±———————————————————————————+
8 rows in set (0.00 sec)

查主库的845133e9-1404-11ea-a37b-005056991dcd:1-4事务:
[mysql@testdb1:/mysqllog]>mysqlbinlog -vv mysql-bin.000001
SET @@SESSION.GTID_NEXT= ‘845133e9-1404-11ea-a37b-005056991dcd:4’/!/;
CREATE USER ‘testing’@’%’ IDENTIFIED WITH ‘mysql_native_password’
SET @@SESSION.GTID_NEXT= ‘AUTOMATIC’ /* added by mysqlbinlog / /!*/;
DELIMITER ;
#End of log file

查询从库4677ee4c-1404-11ea-80dd-00505699b577:1事务
[mysql@testdb2:/mysqllog]>mysqlbinlog -vv mysql-bin.000001
SET @@SESSION.GTID_NEXT= ‘4677ee4c-1404-11ea-80dd-00505699b577:1’/!/;
CREATE USER ‘testing’@’%’ IDENTIFIED WITH ‘mysql_native_password’
SET @@SESSION.GTID_NEXT= ‘AUTOMATIC’ /* added by mysqlbinlog / /!*/;
DELIMITER ;
End of log file

确认是从库已经创建test@’%‘用户,要回放主库创建test@’%’创建用户动作就会失败。

如何处理:
从库
mysql> stop slave;
mysql> reset master;
Query OK, 0 rows affected (0.04 sec)

mysql> set global gtid_purged=‘845133e9-1404-11ea-a37b-005056991dcd:1-4’;
Query OK, 0 rows affected (0.00 sec)

mysql>start slave;

mysql> show slave status \G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: testdb1
Master_User: repusr
Master_Port: 3819
Connect_Retry: 60
Master_Log_File: mysql-bin.000001
Read_Master_Log_Pos: 883
Relay_Log_File: relay-bin.000003
Relay_Log_Pos: 454
Relay_Master_Log_File: mysql-bin.000001
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 883
Relay_Log_Space: 1597
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: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 2624198899
Master_UUID: 845133e9-1404-11ea-a37b-005056991dcd
Master_Info_File: /mysqldata/mysql/data/data/master.info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set: 845133e9-1404-11ea-a37b-005056991dcd:1-4
Executed_Gtid_Set: 845133e9-1404-11ea-a37b-005056991dcd:1-4
Auto_Position: 1
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:

从库
mysql> show master status \G;
*************************** 1. row ***************************
File: mysql-bin.000001
Position: 154
Binlog_Do_DB:
Binlog_Ignore_DB:
Executed_Gtid_Set: 845133e9-1404-11ea-a37b-005056991dcd:1-4
1 row in set (0.00 sec)

ERROR:
No query specified

mysql>
mysql> show global variables like ‘%gtid%’;
±———————————±—————————————–+
| Variable_name | Value |
±———————————±—————————————–+
| binlog_gtid_simple_recovery | ON |
| enforce_gtid_consistency | ON |
| gtid_executed | 845133e9-1404-11ea-a37b-005056991dcd:1-4 |
| gtid_executed_compression_period | 1000 |
| gtid_mode | ON |
| gtid_owned | |
| gtid_purged | 845133e9-1404-11ea-a37b-005056991dcd:1-4 |
| session_track_gtids | OFF |
±———————————±—————————————–+
8 rows in set (0.00 sec)

mysql>

主库
mysql> show master status \G;
*************************** 1. row ***************************
File: mysql-bin.000001
Position: 883
Binlog_Do_DB:
Binlog_Ignore_DB:
Executed_Gtid_Set: 845133e9-1404-11ea-a37b-005056991dcd:1-4
1 row in set (0.00 sec)

ERROR:
No query specified

mysql> show global variables like ‘%gtid%’;
±———————————±——————————————+
| Variable_name | Value |
±———————————±——————————————+
| binlog_gtid_simple_recovery | ON |
| enforce_gtid_consistency | ON |
| gtid_executed | 845133e9-1404-11ea-a37b-005056991dcd:1-4 |
| gtid_executed_compression_period | 1000 |
| gtid_mode | ON |
| gtid_owned | 845133e9-1404-11ea-a37b-005056991dcd:6#89 |
| gtid_purged | |
| session_track_gtids | OFF |
±———————————±——————————————+
8 rows in set (0.01 sec)

总结:
1、确认从库报错1396
Last_Errno: 1396
Last_Error: Coordinator stopped because there were error(s) in the worker(s). The most recent failure being: Worker 0 failed executing transaction ‘845133e9-1404-11ea-a37b-005056991dcd:4’ at master log mysql-bin.000001, end_log_pos 883. See error log and/or performance_schema.replication_applier_status_by_worker table for more details about this failure or others, if any.
2、通过mysqlbinlog 查询相关的主库和从库gitd事务,确认是重复创建用户导致。
3、从库处理步骤:
mysql> stop slave;
mysql> reset master;
mysql> set global gtid_purged=‘845133e9-1404-11ea-a37b-005056991dcd:1-4’;
mysql>start slave;

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/169957.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • windows phone模拟器安卓版_安卓模拟器win7

    windows phone模拟器安卓版_安卓模拟器win7XNAGameStudio 游戏循环在这部分中您将重点两剩余部分的游戏 — — 重写Update 和 Draw 功能。有些大大可能看过相关微软的训练包,我这里主要是帮一些初学者。希望各位大大包含,毕竟文章发出来还是有工作量的。大家觉得有用就好,要是没有耽误时间给大家道个歉。(感谢http://winphone.us/)1.       打开 BackgroundScreen.c

    2022年8月30日
    4
  • 解决SqlTransaction用尽的问题

    解决SqlTransaction用尽的问题解决SqlTransaction用尽的问题有时候程序处理的数据量比较小时,四平八稳,一切安然无恙,但数据量一大,原先潜伏的问题就暴露无遗了。我做的一个项目,是负责一个厂的考勤的。厂里有员工1000多号人。按每人每天打4次卡,一个月30天,则产生的考勤记录数目为1000*4*30=120,000条。在处理这些记录时,我采用的办法是先生成SQL语句,然后执行这些SQL语句:Sql…

    2022年5月4日
    55
  • Python脚本语言第一行的写法「建议收藏」

    Python脚本语言第一行的写法「建议收藏」脚本语言的第一行,目的就是指出,你想要你的这个文件中的代码用什么可执行程序去运行它,就这么简单#!/usr/bin/python是告诉操作系统执行这个脚本的时候,调用/usr/bin下的python

    2022年7月6日
    34
  • oracle数据库超大表名更改,oracle如何修改表名_数据库,oracle,修改表名[通俗易懂]

    oracle数据库超大表名更改,oracle如何修改表名_数据库,oracle,修改表名[通俗易懂]Oracle建表语句是什么_数据库Oracle建表语句是CREATETABLEtablename(column_namedatatype)。其中tablename是要创建的表名,column_name是字段名,datatype是字段类型。oracle如何修改表名方式一altertableold_table_namerenametonew_table_name;这是最简单的(个人认…

    2022年5月16日
    39
  • visualSFM「建议收藏」

    visualSFM「建议收藏」visualSFM:http://ccwu.me/vsfm/ (Avisualstructurefrommotionsysytem)     visualSFM是一个使用SFM方法(structurefrommotion)用于3D重建的GUI应用,这个重建系统融合了ChangchangWu的先前的几个工程:SIFTonGPU(SiftGPU), Multic

    2022年6月20日
    51
  • docker搭建LDAP统一用户认证

    docker搭建LDAP统一用户认证1 安装 LDAPdockerru dit p389 389 v data ldap ldap var lib ldap v data ldap slapd d etc ldap slapd d nameldap envLDA

    2025年7月4日
    2

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号