mysql trouble shooting---- 从库停止同步lock_wait_timeout_exceeded_try_restarting_transaction
问题描述:
数据库从库停止同步。
问题分析:
show slave status\G;(也可使用show full processlist)
显示 某个update语句出错,Lock wait timeout exceeded; try restarting transaction;
原因是这条语句提交的时候超时堵塞。原因在于另外的一个操作开启了事务,锁定了相应的数据,导致这条操作相同数据的sql出错。
示例,在sql中
(1)开启事务,锁定数据
终端A:
mysql> begin; (开启事务,开启事务会锁定相关数据)
Query OK, 0 rows affected (0.00 sec)
mysql> update pet set sex="m" where name="Fluffy";(修改)
Query OK, 1 row affected (0.03 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select * from pet;
+--------+--------+---------+------+------------+------------+
| name | owner | species | sex | birth | death |
+--------+--------+---------+------+------------+------------+
| Bowser | Diane | dog | m | 1979-08-31 | 1995-07-29 |
| Buffy | Harold | dog | f | 1989-05-13 | NULL |
| Claws | Gwen | cat | m | 1994-03-17 | NULL |
| Fang | Benny | dog | m | 2013-02-05 | NULL |
| Fluffy | Harold | cat | m | 2012-09-30 | NULL |
+--------+--------+---------+------+------------+------------+
5 rows in set (0.00 sec)
终端B:
mysql> select * from pet;
+--------+--------+---------+------+------------+------------+
| name | owner | species | sex | birth | death |
+--------+--------+---------+------+------------+------------+
| Bowser | Diane | dog | m | 1979-08-31 | 1995-07-29 |
| Buffy | Harold | dog | f | 1989-05-13 | NULL |
| Claws | Gwen | cat | m | 1994-03-17 | NULL |
| Fang | Benny | dog | m | 2013-02-05 | NULL |
| Fluffy | Harold | cat | NULL | 2012-09-30 | NULL |
+--------+--------+---------+------+------------+------------+
5 rows in set (0.01 sec)
因为没有提交,所以实际上没有改变。但是会锁定Fluffy这一条数据。导致如下的错误。
终端B:
mysql> update pet set sex="m" where name="Fluffy";
ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction
(2)提交事务,解锁数据
终端A:
mysql> commit;
Query OK, 0 rows affected (0.10 sec)
终端B:
mysql> select * from pet;
+--------+--------+---------+------+------------+------------+
| name | owner | species | sex | birth | death |
+--------+--------+---------+------+------------+------------+
| Bowser | Diane | dog | m | 1979-08-31 | 1995-07-29 |
| Buffy | Harold | dog | f | 1989-05-13 | NULL |
| Claws | Gwen | cat | m | 1994-03-17 | NULL |
| Fang | Benny | dog | m | 2013-02-05 | NULL |
| Fluffy | Harold | cat | m | 2012-09-30 | NULL |
+--------+--------+---------+------+------------+------------+
5 rows in set (0.00 sec)
mysql> update pet set sex="f" where name="Fluffy";
Query OK, 1 row affected (0.08 sec)
Rows matched: 1 Changed: 1 Warnings: 0
(3)如果where中的条件是索引字段,那么只会锁定索引对应的条目;如果不是索引字段,那么会锁定整张表。
终端A:
mysql> update pet set sex="f" where death="1995-07-29";
Query OK, 1 row affected (0.03 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select * from pet;
+--------+--------+---------+------+------------+------------+
| name | owner | species | sex | birth | death |
+--------+--------+---------+------+------------+------------+
| Bowser | Diane | dog | f | 1979-08-31 | 1995-07-29 |
| Buffy | Harold | dog | f | 1989-05-13 | NULL |
| Claws | Gwen | cat | m | 1994-03-17 | NULL |
| Fang | Benny | dog | m | 2013-02-05 | NULL |
| Fluffy | Harold | cat | f | 2012-09-30 | NULL |
+--------+--------+---------+------+------------+------------+
5 rows in set (0.00 sec)
终端B:
mysql> select * from pet;
+--------+--------+---------+------+------------+------------+
| name | owner | species | sex | birth | death |
+--------+--------+---------+------+------------+------------+
| Bowser | Diane | dog | m | 1979-08-31 | 1995-07-29 |
| Buffy | Harold | dog | f | 1989-05-13 | NULL |
| Claws | Gwen | cat | m | 1994-03-17 | NULL |
| Fang | Benny | dog | m | 2013-02-05 | NULL |
| Fluffy | Harold | cat | f | 2012-09-30 | NULL |
+--------+--------+---------+------+------------+------------+
5 rows in set (0.00 sec)
mysql> update pet set death="2013-07-00" where birth="2013-02-05";
ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction
解决办法
(1) stop slave; start slave
(2)网上分析说
Mysql 'Lock wait timeout exceeded; try restarting transaction' 解决方案
ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction
Temporary error: 266: Time-out in NDB, probably caused by deadlock 解决方法:在管理节点的[ndbd default]
区加:
TransactionDeadLockDetectionTimeOut=10000(设置为10秒)默认是1200(1.2秒)按照顺序重新启动各个节点就不会出现问题了。
不过,本身貌似数据库的TransactionDeadLockDetectionTimeOut已经设置很大,而且即使设置很大,如果那边一直锁表,也是解决不了问题的。
mysql trouble shooting---- 从库停止同步lock_wait_timeout_exceeded_try_restarting_transaction的更多相关文章
- 不停止MySQL服务增加从库的两种方式
不停止MySQL服务增加从库的两种方式 转载自:http://lizhenliang.blog.51cto.com/7876557/1669829 现在生产环境MySQL数据库是一主一从,由于业务量访 ...
- 不停止MySQL服务增加从库的两种方式【转载】
现在生产环境MySQL数据库是一主一从,由于业务量访问不断增大,故再增加一台从库.前提是不能影响线上业务使用,也就是说不能重启MySQL服务,为了避免出现其他情况,选择在网站访问量低峰期时间段操作. ...
- MYSQL双主全库同步复制
环境: A.B两台服务器分别安装mysql-5.7.18服务端,配置成互为主从同步. linux系统版本为CentOS7 A服务器ip:192.168.1.7 主机名:test1 B服务器ip:1 ...
- 忽略mysql库的同步
忽略mysql库的同步,请使用: stop slave sql_thread; change replication filter replicate_ignore_db=(mysql);
- mysql主从架构,IO、SQL线程运行为YES,从库没有同步数据
mysql基于binlog主从复制架构,IO.SQL线程运行为YES,从库没有同步数据 Slave_IO_Running: Yes Slave_SQL_Running: Yes Replicate_D ...
- 不停mysql服务添加从库的两种方式
现在生产环境MySQL数据库是一主一从,由于业务量访问不断增大,故再增加一台从库.前提是不能影响线上业务使用,也就是说不能重启MySQL服务,为了避免出现其他情况,选择在网站访问量低峰期时间段操作. ...
- Mysql 实现基于binlog的主从同步
工作原理 1.主节点必须启用二进制日志,记录任何修改了数据库数据的事件.2.从节点开启一个线程(I/O Thread)把自己扮演成 mysql 的客户端,通过 mysql 协议,请求主节点的二进制日志 ...
- MySQL主主互备不同步的解决方法
MySQL主主互备不同步 首先在服务器上执行show slave satus;可以看到很多同步的参数: Master_Log_File: SLAVE中的I/O线程当前正在读取的主服务器二进制日志文件的 ...
- MySQL 5.7 深度解析: 半同步复制技术
复制架构衍生史 在谈这个特性之前,我们先来看看MySQL的复制架构衍生史. MySQL的复制分为四种: 普通的replication,异步同步. 搭建简单,使用非常广泛,从mysql诞生之初,就产生了 ...
随机推荐
- ExceL转PDF
using System; using System.Collections.Generic; using System.Linq; using System.Text; using Excel = ...
- 转 Windows 7设置定时自动执行任务方法
在使用电脑的时候可能会遇到一些需要无人值守让电脑自行执行任务后定时关机的情形,在Win7系统中,我们可以使用"任务计划"设置功能结合 shutdown命令灵活设置任务计划,让Win ...
- UVA 10277 Boastin' Red Socks
#include <iostream> #include<cstdio> #include<cstring> using namespace std; unsign ...
- lucene特殊字符处理
这是个郁闷的问题,今天遇到了,但在lucene中查询的关键字保护有特殊字符,譬如--,会出现如下异常: org.apache.lucene.queryParser.ParseException: Ca ...
- cocos2d-x 3.x 橡皮擦功能
1.HelloWorldScene.h cocos2d::DrawNode* _eraser; cocos2d::RenderTexture*_renderTexture; 2.HelloWorldS ...
- Java程序员的10道XML面试题 (转)
包括web开发人员的Java面试在内的各种面试中,XML面试题在各种编程工作的面试中很常见.XML是一种成熟的技术,经常作为从一个平台到其他平台传输数据的标准.XML面试问题包括用于转换XML文件的X ...
- C#中:函数访问级别对函数形参访问级别的约束
Inconsistent accessibility: parameter type 'Program.CommandLineInfo' is less accessible than method ...
- 激活OFFICE2010时,提示choice.exe不是有效的win32程序
我在安装office2010破解版时,提示choice.exe不是有效的win32应用程序 删除choice.exe再激活,按提示找到目录删掉这个文件,需要设置显示隐藏文件夹
- linux常用命令 、查看日志、web排查
linux常用命令 ps aux|grep xxx (比如 ps aux|grep tomcat ps aux|grep tomcat-portalvip ps aux|grep nginx 等) r ...
- 此博客停止更新,请访问chenshuo.net
非常感谢博客园,该博客不在更新,请访问 chenshuo.net