mysql trouble shooting---- 从库停止同步lock_wait_timeout_exceeded_try_restarting_transaction
来源:互联网 发布:linux命令echo使用简介 编辑:程序博客网 时间:2024/05/01 15:14
问题描述:
数据库从库停止同步。
问题分析:
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秒)按照顺序重新启动各个节点就不会出现问题了。
- mysql trouble shooting---- 从库停止同步lock_wait_timeout_exceeded_try_restarting_transaction
- Trouble Shooting
- trouble shooting
- MySql cluster的学习心得 & Trouble shooting
- Trouble Shooting -- Mysql 5.7 Non-install for windows 10
- XL Trouble Shooting
- WASCE trouble shooting
- Eclipse trouble shooting
- Android trouble shooting 整理
- FreeNX trouble shooting
- TROUBLE SHOOTING: FRM-30425
- Server problem trouble shooting
- Linux trouble shooting
- OpenStack Trouble Shooting
- dotNET Trouble Shooting
- .net trouble shooting
- Java Trouble Shooting
- Jenkins-Git trouble shooting
- 判断ios中是否安装了某些软件
- hook之你我之见
- Revit 学习资源
- PHP的SOAP原理及实现
- linux下添加自签名根证书的脚本
- mysql trouble shooting---- 从库停止同步lock_wait_timeout_exceeded_try_restarting_transaction
- MySQL 获取农历月份函数
- android statusbar service
- 基于storm和hadoop的广告系统研究【6】
- 实现web页面局部动态刷新
- COM组件应用(3)——BHO学习
- android SystemClock
- UIAlertView message 居左对齐 显示ios7以后不能用的启发
- MySQL 获取农历日期函数