ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction

本文涉及的产品
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
简介:

前言:朋友说我运行一个简单的建议update声明失败。症状,如下面:
mysql> update order_info  set province_id=15  ,city_id= 1667  where order_from=10 and order_out_sn='1407261241xxxx';
ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction
mysql> 

QQ远程过去。開始check
1,查看数据库的隔离级别:

mysql> select @@tx_isolation;
+-----------------+
| @@tx_isolation  |
+-----------------+
| REPEATABLE-READ |
+-----------------+
1 row in set (0.00 sec)

mysql> 

 
2。去查看先当前库的线程情况:

mysql> show full processlist;

+----------+-----------------+-------------------+-----------------+-------------+---------+-------------------------+-----------------------+

| Id       | User            | Host              | db              | Command     | Time    | State                   | Info                  |

+----------+-----------------+-------------------+-----------------+-------------+---------+-------------------------+-----------------------+

|        1 | event_scheduler | localhost         | NULL            | Daemon      | 9635385 | Waiting on empty queue  | NULL                  |

|  9930577 | business_web    | 192.168.1.21:45503 | business_db     | Sleep       |     153 |                         | NULL                  |

|  9945825 | business_web    | 192.168.1.25:49518 | business_db     | Sleep       |      43 |                         | NULL                  |

|  9946322 | business_web    | 192.168.1.23:44721 | business_db     | Sleep       |     153 |                         | NULL                  |

|  9960167 | business_web    | 192.168.3.28:2409  | business_db     | Sleep       |      93 |                         | NULL                  |

|  9964484 | business_web    | 192.168.1.21:24280 | business_db     | Sleep       |       7 |                         | NULL                  |

|  9972499 | business_web    | 192.168.3.28:35752 | business_db     | Sleep       |      13 |                         | NULL                  |

| 10000117 | business_web    | 192.168.3.28:9149  | business_db     | Sleep       |       6 |                         | NULL                  |

| 10002523 | business_web    | 192.168.3.29:42872 | business_db     | Sleep       |       6 |                         | NULL                  |

| 10007545 | business_web    | 192.168.1.21:51379 | business_db     | Sleep       |     155 |                         | NULL                  |
......

+----------+-----------------+-------------------+-----------------+-------------+---------+-------------------------+-----------------------+

 

没有看到正在运行的慢SQL记录线程。再去查看innodb的事务表INNODB_TRX。看下里面是否有正在锁定的事务线程,看看ID是否在show full processlist里面的sleep线程中,假设是,就证明这个sleep的线程事务一直没有commit或者rollback而是卡住了,我们须要手动kill掉。

 

mysql> SELECT * FROM information_schema.INNODB_TRX\G;

*************************** 1. row ***************************

                    trx_id: 20866

                 trx_state: LOCK WAIT

               trx_started: 2014-07-31 10:42:35

     trx_requested_lock_id: 20866:617:3:3

          trx_wait_started: 2014-07-30 10:42:35

                trx_weight: 2

       trx_mysql_thread_id: 9930577

                 trx_query: delete from dltask where id=1

       trx_operation_state: starting index read

         trx_tables_in_use: 1

         trx_tables_locked: 1

          trx_lock_structs: 2

     trx_lock_memory_bytes: 376

           trx_rows_locked: 1

         trx_rows_modified: 0

   trx_concurrency_tickets: 0

       trx_isolation_level: READ COMMITTED

         trx_unique_checks: 1

    trx_foreign_key_checks: 1

trx_last_foreign_key_error: NULL

 trx_adaptive_hash_latched: 0

 trx_adaptive_hash_timeout: 10000

          trx_is_read_only: 0

trx_autocommit_non_locking: 0

 

3。看到有这条9930577的sql,kill掉。运行kill 9930577;

mysql> kill 9930577;

Query OK, 0 rows affected (0.00 sec)

 

mysql>

 

然后再去查询INNODB_TRX表。就没有堵塞的事务sleep线程存在了。例如以下所看到的:

mysql> SELECT * FROM INNODB_TRX\G;

Empty set (0.00 sec)

 

ERROR:

No query specified

 

mysql>

再去运行update语句,就能正常运行了。例如以下所看到的:

mysql> update order_info  set province_id=15  ,city_id= 1667  where order_from=10 and order_out_sn='1407261241xxxx';

Query OK, 1 row affected (0.00 sec)

Rows matched: 1  Changed: 1  Warnings: 0

 

mysql>

4。总结分析
表数据量也不大,依照普通的情况来说,简单的update应该不会造成堵塞的,mysql都是autocommit,不会出现update卡住的情况,去查看下autocommit的值。
mysql> select @@autocommit;
+--------------+
| @@autocommit |
+--------------+
|            0 |
+--------------+
1 row in set (0.00 sec)


mysql>

看到亮闪闪的0,这个设置导致原来的update语句假设没有commit的话,你再又一次运行update语句,就会等待锁定,当等待时间过长的时候,就会报ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction的错误。
所以赶紧commit刚才运行的update语句,之后 set global autocommit=1;

来自:http://blog.itpub.net/26230597/viewspace-1242948/

版权声明:本文博客原创文章,博客,未经同意,不得转载。




本文转自mfrbuaa博客园博客,原文链接:http://www.cnblogs.com/mfrbuaa/p/4682942.html,如需转载请自行联系原作者


相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
5月前
|
关系型数据库 MySQL 数据库
MySQL报错:Lock wait timeout exceeded; try restarting transaction
MySQL报错:Lock wait timeout exceeded; try restarting transaction
|
5月前
|
SQL 关系型数据库 MySQL
MySQL报错:1205 Lock wait timeout exceeded; try restarting transaction处理
MySQL报错:1205 Lock wait timeout exceeded; try restarting transaction处理
|
6月前
|
SQL 关系型数据库 MySQL
【MySQL异常】MySQL事务锁问题----lock wait timeout exceeded; try restarting transaction
【MySQL异常】MySQL事务锁问题----lock wait timeout exceeded; try restarting transaction
50 0
|
9月前
|
SQL 关系型数据库 MySQL
Mysql 异常:Lock wait timeout exceeded; try restarting transaction的解决办法
Mysql 异常:Lock wait timeout exceeded; try restarting transaction的解决办法
103 0
|
9月前
|
SQL 关系型数据库 MySQL
mysql Lock wait timeout exceeded; try restarting transaction解决方案
在测试程序时,打的断点怎么都跳不进去,console一直报 “Lock wait timeout exceeded; try restarting transaction”
108 0
|
9月前
|
SQL 关系型数据库 MySQL
Lock wait timeout exceeded; try restarting transaction解决方案
在测试程序时,打的断点怎么都跳不进去,console一直报 “Lock wait timeout exceeded; try restarting transaction”
292 0
|
10月前
|
SQL 关系型数据库 MySQL
|
SQL 关系型数据库 MySQL
Deadlock found when trying to get lock; try restarting transaction
Deadlock found when trying to get lock; try restarting transaction
244 1
|
关系型数据库 MySQL
jdbs学习中的错误总结1(MySql Lock wait timeout exceeded)
错误原因: 两个事物之间出现死锁,导致另外一个事物超时 某一种表频繁被锁表,导致其他事物无法拿到锁,导致事物超时
jdbs学习中的错误总结1(MySql Lock wait timeout exceeded)
|
关系型数据库 MySQL 数据库
MySQL - Lock wait timeout exceeded; try restarting transaction
MySQL - Lock wait timeout exceeded; try restarting transaction
344 0
MySQL - Lock wait timeout exceeded; try restarting transaction

热门文章

最新文章