mysql 同步失败_线上MYSQL同步报错故障处理方法总结
前言
在发生故障切换后,经常遇到的问题就是同步报错,下面是最近收集的报错信息。
记录删除失败
在master上删除一条记录,而slave上找不到
Last_SQL_Error: Could not execute Delete_rows event on table hcy.t1;
Can't find record in 't1', Error_code: 1032; handler error HA_ERR_KEY_NOT_FOUND; the event's master log mysql-bin.000006, end_log_pos 254
解决方法:master要删除一条记录,而slave上找不到报错,这种情况主都已经删除了,那么从机可以直接跳过。
stop slave;
set global sql_slave_skip_counter=1;
start slave;
如果这种情况很多,需要针对这种错误专门写相关脚本。
主键重复
在slave已经有该记录,又在master上插入了同一条记录。
Last_SQL_Error: Could not execute Write_rows event on table hcy.t1;
Duplicate entry '2' for key 'PRIMARY',
Error_code: 1062;
handler error HA_ERR_FOUND_DUPP_KEY; the event's master log mysql-bin.000006, end_log_pos 924
解决方法:
在slave上用desc hcy.t1; 先看下表结构:
mysql> desc hcy.t1;
+-------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+-------+
| id | int(11) | NO | PRI | 0 | |
| name | char(4) | YES | | NULL | |
+-------+---------+------+-----+---------+-------+
删除重复的主键
mysql> delete from t1 where id=2;
Query OK, 1 row affected (0.00 sec)
mysql> start slave;
Query OK, 0 rows affected (0.00 sec)
mysql> show slave status\G;
……
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
……
mysql> select * from t1 where id=2;
在master上和slave上再分别确认一下。
更新丢失
在master上更新一条记录,而slave上找不到,丢失了数据。
Last_SQL_Error: Could not execute Update_rows event on table hcy.t1;
Can't find record in 't1', Error_code: 1032; handler error HA_ERR_KEY_NOT_FOUND; the event's master log mysql-bin.000010, end_log_pos 794
解决方法:
在master上,用mysqlbinlog 分析下出错的binlog日志在干什么。
/usr/local/mysql/bin/mysqlbinlog --no-defaults -v -v --base64-output=DECODE-ROWS mysql-bin.000010 | grep -A '10' 794
#120302 12:08:36 server id 22 end_log_pos 794 Update_rows: table id 33 flags: STMT_END_F
### UPDATE hcy.t1
### WHERE
### @1=2 /* INT meta=0 nullable=0 is_null=0 */
### @2='bbc' /* STRING(4) meta=65028 nullable=1 is_null=0 */
### SET
### @1=2 /* INT meta=0 nullable=0 is_null=0 */
### @2='BTV' /* STRING(4) meta=65028 nullable=1 is_null=0 */
# at 794
#120302 12:08:36 server id 22 end_log_pos 821 Xid = 60
COMMIT/*!*/;
DELIMITER ;
# End of log file
ROLLBACK /* added by mysqlbinlog */;
/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
在slave上,查找下更新后的那条记录,应该是不存在的。
mysql> select * from t1 where id=2;
Empty set (0.00 sec)
然后再到master查看
mysql> select * from t1 where id=2;
+----+------+
| id | name |
+----+------+
| 2 | BTV |
+----+------+
1 row in set (0.00 sec)
把丢失的数据在slave上填补,然后跳过报错即可。
mysql> insert into t1 values (2,'BTV');
Query OK, 1 row affected (0.00 sec)
mysql> select * from t1 where id=2;
+----+------+
| id | name |
+----+------+
| 2 | BTV |
+----+------+
1 row in set (0.00 sec)
mysql> stop slave ;set global sql_slave_skip_counter=1;start slave;
Query OK, 0 rows affected (0.01 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
mysql> show slave status\G;
……
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
……
1236错误, 二进制文件缺失
误删二进制文件等各种原因,导致主库mysql-bin.000012文件丢失,从库同步失败。
Master_Log_File: mysql-bin.000012
Slave_IO_Running: No
Slave_SQL_Running: Yes
Last_IO_Error: Got fatal error 1236 from master when reading data from binary log: 'Could not find first log file name in binary log index file'
首先停止从库同步
slave stop;
查看主库日志文件和位置
mysql> show master logs;
+------------------+-----------+
| Log_name | File_size |
+------------------+-----------+
| mysql-bin.000013 | 154 |
+------------------+-----------+
回从库,使日志文件和位置对应主库
CHANGE MASTER TO MASTER_LOG_FILE='log-bin.000013',MASTER_LOG_POS=154;
最后,启动从库:
```bash
slave start;
show slave status\G;
Master_Log_File: mysql-bin.000013
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Last_IO_Error:
```
中继日志损坏
slave的中继日志relay-bin损坏。
Last_SQL_Error: Error initializing relay log position: I/O error reading the header from the binary log
Last_SQL_Error: Error initializing relay log position: Binlog has bad magic number;
It's not a binary log file that can be used by this version of MySQL
1、手工修复
解决方法:找到同步的binlog和POS点,然后重新做同步,这样就可以有新的中继日值了。
例子:
mysql> show slave status\G;
*************************** 1. row ***************************
Master_Log_File: mysql-bin.000010
Read_Master_Log_Pos: 1191
Relay_Log_File: vm02-relay-bin.000005
Relay_Log_Pos: 253
Relay_Master_Log_File: mysql-bin.000010
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: 1593
Last_Error: Error initializing relay log position: I/O error reading the header from the binary log
Skip_Counter: 1
Exec_Master_Log_Pos: 821
Slave_IO_Running :接收master的binlog信息
Master_Log_File
Read_Master_Log_Pos
Slave_SQL_Running:执行写操作
Relay_Master_Log_File
Exec_Master_Log_Pos
以执行写的binlog和POS点为准。
Relay_Master_Log_File: mysql-bin.000010
Exec_Master_Log_Pos: 821
mysql> stop slave;
Query OK, 0 rows affected (0.01 sec)
mysql> CHANGE MASTER TO MASTER_LOG_FILE='mysql-bin.000010',MASTER_LOG_POS=821;
Query OK, 0 rows affected (0.01 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.8.22
Master_User: repl
Master_Port: 3306
Connect_Retry: 10
Master_Log_File: mysql-bin.000010
Read_Master_Log_Pos: 1191
Relay_Log_File: vm02-relay-bin.000002
Relay_Log_Pos: 623
Relay_Master_Log_File: mysql-bin.000010
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: 1191
Relay_Log_Space: 778
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:
mysql 同步失败_线上MYSQL同步报错故障处理方法总结相关推荐
- mysql爆内存_线上MySQL数据库机器内存爆掉原因分析与解决
本文主要向大家介绍了线上MySQL数据库机器内存爆掉原因分析与解决,通过具体的内容向大家展现,希望对大家学习MySQL数据库有所帮助. 现象: 阿里金融某业务的MySQL机器的内存每隔几天就会增长,涨 ...
- mysql内存爆_线上MySQL机器内存爆掉原因分析与解决
现象: 阿里金融某业务的MySQL机器的内存每隔几天就会增长,涨上去后,却不下来.累积后内存爆掉. 分析: 此业务是间隔的对MySQL有大访问,其它时间几乎无访问.排查发现,内存涨时,一般会有MySQ ...
- mac上安装webpack报错解决方法Hit error EACCES: permission denied, mkdir ‘/usr/local/lib/node_modules/webpack
mac上安装webpack报错解决方法Hit error EACCES: permission denied, mkdir '/usr/local/lib/node_modules/webpack 参 ...
- doctor mysql数据导入_线上环境mysql主从同步的搭建过程
之前搭建过一套主从同步的mysql集群,但是是基于新数据库,而这次线上环境要升级成主从同步的集群,记录一下升级过程和中间遇到的各种问题. 由于是直接对线上数据库进行修改,因此要保证对线上环境造成尽量小 ...
- linux备份mysql需要暂停服务吗_【MySQL运维】线上MySQL数据库停服迁移流程
一.数据备份与恢复阶段,选在凌晨1点进行操作,暂停服务进行备份(允许停服2个小时) 1.首先停止Nginx服务,并且修改数据库用户密码,防止还有新的连接进来 2.杀掉某个用户所有进程 for i in ...
- 线上 mysql连接超时_线上环境数据库连接超时原因
查看线上日志发现了如下的异常: ERROR 500.jsp - Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.Com ...
- MySQL线上优化_线上MySQL千万级大表,如何优化?
前段时间应急群有客服反馈,会员管理功能无法按到店时间.到店次数.消费金额进行排序.经过排查发现是 SQL 执行效率低,并且索引效率低下. 图片来自 Pexels 应急问题 商户反馈会员管理功能无法按到 ...
- mysql 授权 失败_完美解决mysql客户端授权后连接失败的问题
在本地(192.168.1.152)部署好mysql环境,授权远程客户机192.168.1.%连接本机的mysql,在iptables防火墙也已开通3306端口. 如下: mysql> sele ...
- mysql exp 注入_使用exp进行SQL报错注入
0x01 前言概述 好消息好消息-作者又在MySQL中发现了一个Double型数据溢出.如果你想了解利用溢出来注出数据,你可以读一下作者之前发的博文:BIGINT Overflow Error bas ...
最新文章
- Docker swarm集群详解(一)
- ASP导出数据到excel
- VTK:图片之ImageAccumulateGreyscale
- 【tensorflow】全连接层函数tf.layers.dense()原理
- php连接mongoDB的几个问题
- 19 Handler 子线程向主线程发送信息
- 循环序列模型 —— 1.2 数学符号
- [jQuery基础] 初识jQuery
- 清华AI的华山论剑现已开启,不服就来战!王小川楼天城唐文斌都曾搅动风云...
- keras中无法用save保存模型的问题
- flashftp中文绿色破解版免费下载
- mysql instead of触发_在视图上使用 INSTEAD OF 触发器
- 保证线程安全的三种方式
- 移动中兴服务器地址,一中国移动宽带各地dns服务器地址.doc
- 云计算革命-IT产业第三次变革,将如何影响人类社会
- python获取表格中的所有数据_【经验分享】用Python读取电子表格中的数据
- 使用Navicat连接Mycat的诡异事件
- 【转帖】楚狂人的 DriverNetworks开发网络驱动教材(0-7课)
- 笔记本无法连接WiFi
- 人一般长到几岁才会停止长高?
热门文章
- Linux基础——系统安全及应用(su切换用户PAM认证,sudo提权,grub加密,账号密码破解,端口扫描)(十)
- 数据库设计2————需求分析
- 使用Microsoft Edge dev浏览器突然找不到new bing,bing chat消失
- 青少年python系列 27.turtle库绘制一个四叶花瓣
- OpenStack配置使用sriov
- Python的三种主要模块介绍
- 华为设备配置| 高级ACL| 对五元组做配置
- 29个做电商必须知道的计算公式!
- 愿来到我博客的朋友一生温暖纯良,不舍爱与自由。
- python 多分类画auc曲线和macro-average ROC curve