2019独角兽企业重金招聘Python工程师标准>>>

先说我我的解决方法:找到锁住的线程然后kill掉。

mysql> kill thr_id;

下面简单分析一下到底应该kill哪个线程。

show processlist查看所有运行的线程,发现所有线程的状态都是sleep,不清楚这么多sleep的线程,INNODB_TRX表里也没有对应RUNNING的记录,那些线程假死了?

mysql> show full processlist;
+------+------+---------------------+----------+---------+-------+-------+-----------------------+
| Id   | User | Host                | db       | Command | Time  | State | Info                  |
+------+------+---------------------+----------+---------+-------+-------+-----------------------+
| 1172 | root | 112.124.64.64:43083 | eye      | Sleep   | 12384 |       | NULL                  |
| 1179 | root | 112.124.64.64:43086 | eye      | Sleep   |   596 |       | NULL                  |
| 1181 | root | 112.124.64.64:43087 | eye      | Sleep   | 12467 |       | NULL                  |
| 1182 | root | 112.124.64.64:43088 | eye      | Sleep   |   149 |       | NULL                  |
| 1183 | root | 112.124.64.64:43089 | eye      | Sleep   |   612 |       | NULL                  |
| 1184 | root | 112.124.64.64:43090 | eye      | Sleep   |    39 |       | NULL                  |
| 1197 | root | 112.124.64.64:43092 | eye      | Sleep   |   148 |       | NULL                  |
| 1198 | root | 112.124.64.64:43093 | eye      | Sleep   |  5415 |       | NULL                  |
| 1200 | root | 112.124.64.64:43095 | eye      | Sleep   |   581 |       | NULL                  |
| 1289 | root | 58.249.112.63:5657  | eye      | Sleep   |  1496 |       | NULL                  |
| 1325 | root | localhost           | NULL     | Query   |     0 | NULL  | show full processlist |
+------+------+---------------------+----------+---------+-------+-------+-----------------------+

查看information_schema库中的INNODB_TRX表发现有几条记录,时间和用户反馈的时间是对上号的,id号在上结果中也有显示,表列太多,截图没截全:

show engine innodb status发现有以下几行:

---TRANSACTION 17E34B, ACTIVE 3296 sec
2 lock struct(s), heap size 376, 0 row lock(s), undo log entries 15
MySQL thread id 1196, OS thread handle 0x7f1f0759d700, query id 140864 112.124.64.64 root
Trx read view will not see trx with id >= 17E34C, sees < 17DFA9
---TRANSACTION 17E11F, ACTIVE 6222 sec
10 lock struct(s), heap size 3112, 9 row lock(s), undo log entries 11
MySQL thread id 1199, OS thread handle 0x7f1f07458700, query id 140844 112.124.64.64 root
Trx read view will not see trx with id >= 17E120, sees < 17DFA9
---TRANSACTION 17DFAA, ACTIVE 11653 sec
2 lock struct(s), heap size 376, 0 row lock(s), undo log entries 15
MySQL thread id 1178, OS thread handle 0x7f1f0af75700, query id 133760 112.124.64.64 root
Trx read view will not see trx with id >= 17DFAB, sees < 17DFA7
---TRANSACTION 17DFA9, ACTIVE 11655 sec
3 lock struct(s), heap size 376, 1 row lock(s), undo log entries 15
MySQL thread id 1177, OS thread handle 0x7f1f1b682700, query id 133743 112.124.64.64 root
Trx read view will not see trx with id >= 17DFAA, sees < 17DFA7

(TRANSACTION 17DFAA,2 lock struct(s), 0 row lock(s),0 row locks,那 2 lock struct(s)到底锁在了啥上面)【当事务超时之后show engine innodb status就不会显示此事务运行时的执行SQL,以上信息只能说明这个事务锁等待过,2016-08-20】,(不是特别理解"MySQL thread id 1196, OS thread handle 0x7f1f0759d700, query id 140864 112.124.64.64 root Trx read view will not see trx with id >= 17E34C, sees < 17DFA9",有什么提示信息,难道trx_id还必须连续?")【InnoDB使用MVCC来减少锁的使用和开销,允许非阻塞读,写操作时只锁定必要的记录,MVCC工作在READ-COMMITTED,REAPEATABLE-READ隔离级别,通过TRX_ID并发控制,2016-08-20】(undo log entries 15"的意思是15条没有insert进去,还是回滚操作没有回滚回来?)【undo log记录的是没有更改之前的数据,回滚用,这里应该是回滚了的条数,2016-08-20】。

先来尝试还原当时的情景,插入一条数据,因为未知原因事务一直未提交,获得的锁当然未释放,然后再去操作同一条数据两次,查询INNODB_TRX表,发现出现三条数据,前两条是后来更新操作的信息,trx_state字段为LOCK WAIT,第三个是没有提交事务的那条操作:


mysql> select * from INNODB_TRX;
+--------+-----------+---------------------+-----------------------+---------------------+------------+---------------------+---------------------------------------------------------------------------------------------------------------------------------------------+---------------------+-------------------+-------------------+------------------+-----------------------+-----------------+-------------------+-------------------------+---------------------+-------------------+------------------------+----------------------------+---------------------------+---------------------------+
| trx_id | trx_state | trx_started         | trx_requested_lock_id | trx_wait_started    | trx_weight | trx_mysql_thread_id | trx_query                                                                                                                                   | trx_operation_state | trx_tables_in_use | trx_tables_locked | trx_lock_structs | trx_lock_memory_bytes | trx_rows_locked | trx_rows_modified | trx_concurrency_tickets | trx_isolation_level | trx_unique_checks | trx_foreign_key_checks | trx_last_foreign_key_error | trx_adaptive_hash_latched | trx_adaptive_hash_timeout |
+--------+-----------+---------------------+-----------------------+---------------------+------------+---------------------+---------------------------------------------------------------------------------------------------------------------------------------------+---------------------+-------------------+-------------------+------------------+-----------------------+-----------------+-------------------+-------------------------+---------------------+-------------------+------------------------+----------------------------+---------------------------+---------------------------+
| 1852B9 | LOCK WAIT | 2016-05-23 21:09:24 | 1852B9:0:3611:51      | 2016-05-23 21:09:25 |          2 |                7920 | UPDATE inspectionhistory          SET               evaluation = null,             photoName = null             WHERE inspectionID = '000154DD83C3313FA051' | starting index read |                 1 |                 1 |                2 |                   376 |               1 |                 0 |                       0 | REPEATABLE READ     |                 1 |                      1 | NULL                       |                         0 |                      9997 |
| 1852A8 | LOCK WAIT | 2016-05-23 21:09:13 | 1852A8:0:3611:51      | 2016-05-23 21:09:13 |          2 |                7861 | UPDATE inspectionhistory          SET               evaluation = null,             photoName = null             WHERE inspectionID = '000154DD83C3313FA051' | starting index read |                 1 |                 1 |                2 |                   376 |               1 |                 0 |                       0 | REPEATABLE READ     |                 1 |                      1 | NULL                       |                         0 |                      9997 |
| 18529F | RUNNING   | 2016-05-23 21:09:06 | NULL                  | NULL                |         31 |                7863 | NULL                                                                                                                                        | NULL                |                 0 |                 0 |               14 |                  3112 |              17 |                17 |                       0 | REPEATABLE READ     |                 1 |                      1 | NULL                       |                         0 |                      9982 |
+--------+-----------+---------------------+-----------------------+---------------------+------------+---------------------+---------------------------------------------------------------------------------------------------------------------------------------------+---------------------+-------------------+-------------------+------------------+-----------------------+-----------------+-------------------+-------------------------+---------------------+-------------------+------------------------+----------------------------+---------------------------+---------------------------+

上表里前两个事务等待超时返回错误信息,然后INNODB_TRX表里记录自动删除,剩下未提交事务的那条记录,如下:

--- The error occurred in mit/datamodel/ibatis/inspectionhistory.xml.
--- The error occurred while applying a parameter map.
--- Check the updateInspectionHistory-InlineParameterMap.
--- Check the statement (update failed).
--- Cause: java.sql.SQLException: Lock wait timeout exceeded; try restarting transaction
+--------+-----------+---------------------+-----------------------+------------------+------------+---------------------+-----------+---------------------+-------------------+-------------------+------------------+-----------------------+-----------------+-------------------+-------------------------+---------------------+-------------------+------------------------+----------------------------+---------------------------+---------------------------+
| trx_id | trx_state | trx_started         | trx_requested_lock_id | trx_wait_started | trx_weight | trx_mysql_thread_id | trx_query | trx_operation_state | trx_tables_in_use | trx_tables_locked | trx_lock_structs | trx_lock_memory_bytes | trx_rows_locked | trx_rows_modified | trx_concurrency_tickets | trx_isolation_level | trx_unique_checks | trx_foreign_key_checks | trx_last_foreign_key_error | trx_adaptive_hash_latched | trx_adaptive_hash_timeout |
+--------+-----------+---------------------+-----------------------+------------------+------------+---------------------+-----------+---------------------+-------------------+-------------------+------------------+-----------------------+-----------------+-------------------+-------------------------+---------------------+-------------------+------------------------+----------------------------+---------------------------+---------------------------+
| 18529F | RUNNING   | 2016-05-23 21:09:06 | NULL                  | NULL             |         31 |                7863 | NULL      | NULL                |                 0 |                 0 |               14 |                  3112 |              17 |                17 |                       0 | REPEATABLE READ     |                 1 |                      1 | NULL                       |                         0 |                      9982 |
+--------+-----------+---------------------+-----------------------+------------------+------------+---------------------+-----------+---------------------+-------------------+-------------------+------------------+-----------------------+-----------------+-------------------+-------------------------+---------------------+-------------------+------------------------+----------------------------+---------------------------+---------------------------+

当提交事务时,INNODB_TRX表里无记录。

mysql> select * from INNODB_TRX;
Empty set (0.00 sec)

如果真是这样,那么问题来了,(为什么上面截图里面5个事务一直RUNNING状态,什么导致了它们不去提交事务。)【什么导致了5个事务一直RUNNING现在还不清原因,也还原不了了,但是前段时间遇到一种这样的情况,在一次事务没有提交时,我更改了这张表的索引字段,导致卡死,之后强制关闭命令行,再重新打开去show processlist,发现更改索引的那个事务一直RUNNING,2016-08-20】(以至于后来查询其它数据也等待超时,难道是它们之间及到了X,S,GAP锁?或者因为 Trx read view will not see?)【确实是因为没有提交的事务锁定了某些行数据,如果字段没有建索引,会锁住整张表数据,2016-08-20】

ps:无聊时随手看了下INNIDB_TRX表信息,它的Engine竟然是Memory,其实也该想到了,只是经验太少,从没有实践机会去用Memory引擎。

+------------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+-------------+------------+-----------------+----------+----------------+---------+
| Name       | Engine | Version | Row_format | Rows | Avg_row_length | Data_length | Max_data_length | Index_length | Data_free | Auto_increment | Create_time         | Update_time | Check_time | Collation       | Checksum | Create_options | Comment |
+------------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+-------------+------------+-----------------+----------+----------------+---------+
| INNODB_TRX | MEMORY |      10 | Fixed      | NULL |           4534 |           0 |        16766732 |            0 |         0 |           NULL | 2016-05-23 22:06:37 | NULL        | NULL       | utf8_general_ci |     NULL | max_rows=3700  |         |
+------------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+-------------+------------+-----------------+----------+----------------+---------+

转载于:https://my.oschina.net/u/2265029/blog/668023

java.sql.SQLException: Lock wait timeout exceeded相关推荐

  1. java.sql.SQLException: Lock wait timeout exceeded --转

    org.springframework.dao.CannotAcquireLockException 的解决> 直接上 bug 的详细信息: 2012-03-12 15:20:31 XmlBea ...

  2. java lock wait_java.sql.SQLException: Lock wait timeout exceeded; try restarting transaction

    在开发测试过程中发现出了这个问题: RECHARGE:业务,数据: {"platformUserNo":"RPD_1512632756191","am ...

  3. Caused by: java.sql.SQLException: GC overhead limit exceeded处理百万数据出现的异常

    Caused by: java.sql.SQLException: GC overhead limit exceeded处理百万数据出现的异常 参考文章: (1)Caused by: java.sql ...

  4. mysql 中lock wait_应用中MYSQL 报错Lock wait timeout exceeded; try restarting transaction

    最近开发的应用开始做性能测试.在小于80用户并发的时候一切OK,并发量到100用户时,持续压5分钟.应用开始报错,并且只有1次错误,持续时间长,比如10分钟,会报3次. 日志如下: Caused by ...

  5. Lock wait timeout exceeded; try restarting......

    2019独角兽企业重金招聘Python工程师标准>>> mysql异常java.sql.SQLException: Lock wait timeout exceeded; try r ...

  6. mysql死锁释放时间参数_【Mysql】mysql 事务未提交导致死锁 Lock wait timeout exceeded; try restarting transaction 解决办法...

    问题场景 问题出现环境: 1.在同一事务内先后对同一条数据进行插入和更新操作: 2.多台服务器操作同一数据库: 3.瞬时出现高并发现象: 不断的有一下异常抛出,异常信息: org.springfram ...

  7. mysql 告警 异常 处理_mysql异常解决方案 - Lock wait timeout exceeded异常

    问题 最近线上业务在运行过程中,遇到如下异常: 2021-01-13 10:25:20.838 WARN [http-nio-7010-exec-104][SqlExceptionHelper.jav ...

  8. mysql当执行delete语句时备份_mysql中,执行delete语句时出现Lock wait timeout exceeded问题...

    问题描述: 当我插入一条记录时,在调用save方法的时候出现了异常(记录重复了),导致了后面的commit语句不能执行了.这时我在数据库中删除重复记录时发现该表已经被锁上了.即出现 错误.但过了一会再 ...

  9. SQL性能优化常见措施(Lock wait timeout exceeded)

    SQL性能优化常见措施 目 录 1.mysql中explain命令使用 2.mysql中mysqldumpslow的使用 3.mysql中修改my.ini配置文件记录日志 4.mysql中如何加索引 ...

最新文章

  1. java 导出 jar lib_java使用IDEA引入外部jar和导出可执行jar文件的方法
  2. 基于psr规范php框架,PHP-PSR规范
  3. 常见的一些 Hash 函数
  4. window如何杀掉java进程_windows下java -jar 后台运行以及杀死后台进程的操作
  5. 【转载】Asp.Net中基于Forms验证的角色验证授权
  6. 从零开始学电脑_带你从零开始学装机 打造自己的专属电脑之固态和机械硬盘搭配篇...
  7. 好程序员web前端分享MVVM框架Vue实现原理
  8. sublime text 3 , 3143
  9. 云计算和主机托管有哪几点不同?
  10. Mac 安装mysql8
  11. 【读PPT】管中窥豹:用大数据洞察“用户画像”的秘密!
  12. ExtJs 入门教程
  13. C#调用系统打印机(XP-58小票打印)
  14. kmeans聚类算法_常用聚类算法综述
  15. 七周成为数据分析师 第一周:数据分析思维
  16. C语言if语句实现成绩划分
  17. redis缓存服务器
  18. 2021年幼儿园教师招聘:小班梳子画《小草》
  19. 基于asyncio编写一个telegram爬虫机器人
  20. 微生物组-宏基因组分析专题研讨会(2022.8)

热门文章

  1. 下一代搜索引擎长啥样?Google 给出了TA的答案
  2. 迁移学习:如何为您的机器学习问题选择正确的预训练模型
  3. 神经元产生的雌激素可能是一种新型的神经调节剂
  4. 吴恩达深度学习笔记(114)-RNN梯度消失问题详解
  5. 一文看懂5G和AI融合的5个要点
  6. SAP到SAP的升级 --- SAP行业新的金矿
  7. 01_字符串处理-----05_相似性度量
  8. 《数学之美》第25章 条件随机场、文法分析及其他
  9. Centos7为普通用户添加sudo权限
  10. 应对全球粮食危机 AI、5G与机器视觉联手“养鱼”