mysql5.7同步复制报错故障处理

# 报错 1060,具体如下
Last_Errno: 1060
Last_Error: Coordinator stopped because there were error(s) in the worker(s). The most recent failure being: Worker 0 failed executing transaction 'ANONYMOUS' at master log mysql-bin.000311, end_log_pos 352951786. See error log and/or performance_schema.replication_applier_status_by_worker table for more details about this failure or others, if any.

# 可以使用命令查看具体的执行sql语句
# 查找 positions 的位置向后10行
/usr/local/percona-server-5.7.14/bin/mysqlbinlog --no-defaults -v -v --base64-output=DECODE-ROWS mysql-bin.000311 | grep -A 10 352951786

# 用这条语句定位不到具体的执行sql
[root@newcms:/data/mysql_data]# /usr/local/percona-server-5.7.14/bin/mysqlbinlog --base64-output=DECODE-ROWS -v --start-position=352951786 --stop-position=352951786 mysql-bin.000311 | more
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/;
/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
DELIMITER /*!*/;
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*/;

# 推荐使用如下定位命令:
[root@newcms:/data/mysql_data]# /usr/local/percona-server-5.7.14/bin/mysqlbinlog --no-defaults -v -v --base64-output=DECODE-ROWS mysql-bin.000311 | grep -A 10 352951786
#191202  9:13:24 server id 1189  end_log_pos 352951786 CRC32 0xb6b23b6f     Query    thread_id=4299701    exec_time=0    error_code=0
SET TIMESTAMP=1575249204/*!*/;
/*!\C utf8 *//*!*/;
SET @@session.character_set_client=33,@@session.collation_connection=33,@@session.collation_server=45/*!*/;
# 可以看到关键的执行sql语句,添加了字段,并且新增内容
ALTER TABLE `template_page_9342` ADD COLUMN `content` longtext NOT NULL
/*!*/;
# at 352951786
#191202  9:13:24 server id 1189  end_log_pos 352951851 CRC32 0x5636b59f     Anonymous_GTID    last_committed=3226    sequence_number=3227
SET @@SESSION.GTID_NEXT= 'ANONYMOUS'/*!*/;
# at 352951851
#191202  9:13:24 server id 1189  end_log_pos 352951929 CRC32 0x8f64d217     Query    thread_id=4299701    exec_time=0    error_code=0
SET TIMESTAMP=1575249204/*!*/;
BEGIN
/*!*/;
# at 352951929
#191202  9:13:24 server id 1189  end_log_pos 352952048 CRC32 0x96da7aa4     Table_map: `cms_global`.`template_fields` mapped to number 139
# at 352952048

# 对比主库和从库的表结构,可以看到是一致的,直接跳过即可
STOP SLAVE; SET GLOBAL SQL_SLAVE_SKIP_COUNTER = 1; START SLAVE;

# 主库
mysql> desc template_page_9342;
+-------------+----------------------------------+------+-----+---------+----------------+
| Field       | Type                             | Null | Key | Default | Extra          |
+-------------+----------------------------------+------+-----+---------+----------------+
| page_id     | int(10) unsigned                 | NO   | PRI | NULL    | auto_increment |
| title       | char(100)                        | NO   |     | NULL    |                |
| keyword     | char(250)                        | NO   |     | NULL    |                |
| description | char(200)                        | NO   |     | NULL    |                |
| url         | varchar(255)                     | NO   |     | NULL    |                |
| entity_id   | int(10) unsigned                 | NO   |     | NULL    |                |
| entity_name | char(100)                        | NO   |     | NULL    |                |
| is_default  | enum('Y','N')                    | NO   |     | Y       |                |
| html_time   | datetime                         | NO   |     | NULL    |                |
| action_name | char(20)                         | NO   |     | NULL    |                |
| user_id_a   | int(11) unsigned                 | NO   |     | NULL    |                |
| user_id_e   | int(11) unsigned                 | NO   |     | NULL    |                |
| add_time    | datetime                         | NO   |     | NULL    |                |
| edit_time   | datetime                         | NO   |     | NULL    |                |
| user_name   | char(20)                         | NO   |     | NULL    |                |
| state       | enum('able','disable','deleted') | NO   |     | able    |                |
| content     | longtext                         | NO   |     | NULL    |                |
| style       | longtext                         | NO   |     | NULL    |                |
| script      | longtext                         | NO   |     | NULL    |                |
+-------------+----------------------------------+------+-----+---------+----------------+

# 从库
MySQL [cms_global]> desc template_page_9342;
+-------------+----------------------------------+------+-----+---------+----------------+
| Field       | Type                             | Null | Key | Default | Extra          |
+-------------+----------------------------------+------+-----+---------+----------------+
| page_id     | int(10) unsigned                 | NO   | PRI | NULL    | auto_increment |
| title       | char(100)                        | NO   |     | NULL    |                |
| keyword     | char(250)                        | NO   |     | NULL    |                |
| description | char(200)                        | NO   |     | NULL    |                |
| url         | varchar(255)                     | NO   |     | NULL    |                |
| entity_id   | int(10) unsigned                 | NO   |     | NULL    |                |
| entity_name | char(100)                        | NO   |     | NULL    |                |
| is_default  | enum('Y','N')                    | NO   |     | Y       |                |
| html_time   | datetime                         | NO   |     | NULL    |                |
| action_name | char(20)                         | NO   |     | NULL    |                |
| user_id_a   | int(11) unsigned                 | NO   |     | NULL    |                |
| user_id_e   | int(11) unsigned                 | NO   |     | NULL    |                |
| add_time    | datetime                         | NO   |     | NULL    |                |
| edit_time   | datetime                         | NO   |     | NULL    |                |
| user_name   | char(20)                         | NO   |     | NULL    |                |
| state       | enum('able','disable','deleted') | NO   |     | able    |                |
| content     | longtext                         | NO   |     | NULL    |                |
| style       | longtext                         | NO   |     | NULL    |                |
| script      | longtext                         | NO   |     | NULL    |                |
+-------------+----------------------------------+------+-----+---------+----------------+

# 在主库中查找binlog报错,ERROR: Error in Log_event::read_log_event(): 'Sanity check failed' 是因为默认的mysqlbinlog命令是yum安装的低版本mysqlbinlog,需要指定我们运行的mysql高版本的命令
[root@newcms:/data/mysql_data]# mysqlbinlog --no-defaults -v -v --base64-output=DECODE-ROWS mysql-bin.000311 | grep -A 10 352951786
ERROR: Error in Log_event::read_log_event(): 'Sanity check failed', data_len: 31, event_type: 35
ERROR: Could not read entry at offset 123: Error in log format or read error.

[root@newcms:/data/mysql_data]# mysqlbinlog --base64-output=DECODE-ROWS -v --start-position=352951786 --stop-position=352951786 mysql-bin.000311 | more
ERROR: Error in Log_event::read_log_event(): 'Sanity check failed', data_len: 65, event_type: 34
ERROR: Could not read entry at offset 352951786: Error in log format or read error.
/*!40019 SET @@session.max_insert_delayed_threads=0*/;
/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
DELIMITER /*!*/;
DELIMITER ;
# End of log file
ROLLBACK /* added by mysqlbinlog */;
/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;

总结:
在MySQL主从同步集群部署中,经常会遇到主从不能同步的问题,以下对常见问题及解决办法进行了归纳列举

数据不一致:包括删除失败、主键重复、更新丢失
例如:

#更新丢失
Last_SQL_Errno: 1032
Last_SQL_Error: Could not execute Update_rows event on table social.test; Can't find record in 'jason', Error_code: 1032; handler error HA_ERR_KEY_NOT_FOUND;the event's master log mysql-bin.000019, end_log_pos 4563
#主键重复
Last_SQL_Errno: 1062
Last_SQL_Error: Error 'Duplicate entry '1' for key 'PRIMARY'' on query. Default database: 'social'. Query: 'INSERT INTO `social`.`tool`(`createdat`, `updatedat`) VALUES ('2019-06-05 09:11:46', '2019-06-05 09:11:51')'
#删除失败
Last_SQL_Errno: 1032
Last_SQL_Error: Could not execute Delete_rows_v1 event on table social.player_role; Can't find record in 'player_role', Error_code: 1032; handler error HA_ERR_END_OF_FILE; the event's master log mysql-bin.000013, end_log_pos 20064466

在master上,用mysqlbinlog 分析下出错的binlog日志在干什么:

[root@localhost ~]# mysqlbinlog --no-defaults -v -v --base64-output=DECODE-ROWS mysql-bin.000013 | grep -A 10 20064466
#190605  9:12:28 server id 1  end_log_pos 20064466     Delete_rows: table id 442 flags: STMT_END_F
### DELETE FROM `social`.`player_role`
### WHERE
###   @1=1 /* INT meta=0 nullable=0 is_null=0 */
###   @2=1 /* INT meta=0 nullable=0 is_null=0 */
###   @3='2019-06-04 20:10:48' /* DATETIME(0) meta=0 nullable=1 is_null=0 */
###   @4='2019-06-04 20:10:48' /* DATETIME(0) meta=0 nullable=1 is_null=0 */
# at 20064466
#190605  9:12:28 server id 1  end_log_pos 20064493     Xid = 414815
COMMIT/*!*/;
# at 20064493
#190605  9:13:00 server id 1  end_log_pos 20064531     GTID 0-1-9152684 trans
/*!100001 SET @@session.gtid_seq_no=9152684*//*!*/;
BEGIN
/*!*/;
# at 20064531
#190605  9:13:00 server id 1  end_log_pos 20064795     Query    thread_id=1733    exec_time=0    error_code=0
SET TIMESTAMP=1559697180.6860/*!*/;

对于主键重复/删除失败/更新丢失,更新丢失主要是缺少更新的记录,进行补充下即可,主键重复/删除失败此时可以选择忽略错误,方法如下:

mysql> stop slave;
mysql> set global sql_slave_skip_counter=1;
mysql> start slave;
mysql> show slave status\G

字段不一致:包括字段重复、丢失、不够长等
#字段重复
Last_SQL_Errno: 1060
Last_SQL_Error: Error 'Duplicate column name 'del_flag'' on query. Default database: 'social'. Query: 'ALTER TABLE `social`.`player` ADD COLUMN `del_flag` int(11) NULL AFTER `detail`'
对于数据库字段的同步失败,只需要将主从数据库的字段名称、类型等调整一致即可。之后重启slave,查看主从同步是否恢复

主从表不一致
Last_SQL_Errno: 1146
Last_SQL_Error: Error executing row event: 'Table 'social.player_role' doesn't exist'
主从提示缺少表可以进行添加,多余表可以删除,保证主从表的一致即可。之后重启slave,查看主从同步是否恢复

mysql5.7同步复制报错1060故障处理的更多相关文章

  1. ecstore在MySQL5.7下维护报错WARNING:512 @ ALTER IGNORE TABLE

    ecstore在MySQL5.7下维护报错WARNING:512 @ ALTER IGNORE TABLE 打开 /app/base/lib/application/dbtable.php , 替换A ...

  2. mysql5.6版本备份报错

    MySQL5.6版本备份报错,密码不安全 [root@centos199 mysql]# mysqldump -uroot -ppassword cz-office > mysql38.sqlW ...

  3. git同步遇到报错

    git同步遇到报错 “fatal: unable to access ‘https://github.com/ruanwenwu/newp.git/‘: Peer reports incompatib ...

  4. git同步遇到报错“fatal: unable to access 'https://github.com/lizhong24/mysite2.git/': Peer reports incompatible or unsupported protocol version.”

    git同步遇到报错“fatal: unable to access 'https://github.com/lizhong24/mysite2.git/': Peer reports incompat ...

  5. 运维与开发的开车现场之MySQL5.7创建触发器报错解决过程

    报错内容如下: ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds ...

  6. GG同步sqlserver报错一个案例 Invalid date format

    在里面Oracle表同步sqlserver时间,在sqlserver当应用程序数据的结束.您可能会遇到这个错误. 2014-05-17 17:20:24 WARNING OGG-01154 SQL e ...

  7. mysql5.7初始化密码报错 ERROR 1820 (HY000): You must reset your password using ALTER USER statement before

    mysql初始化密码常见报错问题1,mysql5.6是密码为空直接进入数据库的,但是mysql5.7就需要初始密码 cat /var/log/mysqld.log | grep password1 2 ...

  8. mysql5.7初始化密码报错ERROR1820(HY000):YoumustresetyourpasswordusingALTERUSERstateme

    1,mysql5.6是密码为空直接进入数据库的,但是mysql5.7就需要初始密码 cat /var/log/mysqld.log | grep password 或者:grep 'temporary ...

  9. DG环境恢复同步遇到报错ORA-00353ORA-00334以及ORA-00600[2619], [47745]

    问题说明 客户环境主库4节点RAC11.2.0.4,单实例DG环境,DG由于空间不足,导致同步中断,由于DG备库未应用的归档主库都再,本次恢复的方式,是开启dg mrp进程,自动同步追上主库. 以下遇 ...

随机推荐

  1. Hadoop-HA集群搭建-rehl7.4

    Hadoop-HA集群搭建-rehl7.4 hadoop 无说明需要登录其它机器操作,都是在集群的HD-2-101上执行的命令. 所有安装包地址:百度网盘,提取码:24oy 1. 基础环境配置 1.1 ...

  2. 调用python脚本报错/usr/bin/env: python : No such file or directory

    一.调用python脚本报错 /usr/bin/env: python: No such file or directory 二.解决方法 原因是在windows上编写的脚本,使用dos2unix对脚 ...

  3. 配置VScode c语言环境

    vscode 提示 <sys/socket.h>找不到, 原来是不同平台上,头文件不一样. 参考:https://blog.csdn.net/qq_28581077/article/det ...

  4. python老师博客

    前端基础之HTML http://www.cnblogs.com/yuanchenqi/articles/6835654.html 前端基础之CSS http://www.cnblogs.com/yu ...

  5. Flutter 数据存储之 shared_preferences

    资源名称 网址 github https://github.com/flutter/plugins/tree/master/packages/shared_preferences Flutter 数据 ...

  6. 20180606模拟赛T1——猫鼠游戏

    题目描述: 猫和老鼠在10*10的方格中运动,例如: *...*..... ......*... ...*...*.. .......... ...*.C.... *.....*... ...*... ...

  7. Ofbiz项目学习——阶段性小结——视图

    一.简要介绍 1.按照SQL的视图概念:在 SQL 中,视图是基于 SQL 语句的结果集的可视化的表.视图包含行和列,就像一个真实的表.视图中的字段就是来自一个或多个数据库中的真实的表中的字段. 2. ...

  8. v-for给img的src动态赋值问题

    做一个轮播图,给img赋值src <el-carousel-item v-for="(item, index) in carouselImgs" :key="ind ...

  9. SG函数的理解集应用

    转载自知乎牛客竞赛——博弈论入门(函数讲解+真题模板) SG函数 作用 对于一个状态i为先手必胜态当且仅当SG(i)!=0. 转移 那怎么得到SG函数尼. SG(i)=mex(SG(j))(状态i可以 ...

  10. 关于singer elt 的几篇很不错的文章

    以下是链接来自singer 团队的实践,很不错,值得学习 参考连接 https://www.stitchdata.com/blog/100-billion-records-later-refining ...