前言:朋友咨询我说执行简单的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/

ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction相关推荐

  1. 关于MySQL出现`lock wait timeout exceeded; try restarting transaction` 的解决方案

    关于MySQL出现lock wait timeout exceeded; try restarting transaction 的解决方案. 一.问题抛出 在做查询语句时,MySQL 抛出了这样的异常 ...

  2. 关于MySQL出现锁等待lock wait timeout exceeded; try restarting transaction 的解决方案

    关于MySQL出现lock wait timeout exceeded; try restarting transaction 的解决方案. 一.问题抛出 在做查询语句时,MySQL 抛出了这样的异常 ...

  3. 数据库 1205 Error 'Lock wait timeout exceeded; try restarting transaction' on query

    收到报警,mysql的从数据库在同步的过程出现问题,已停止同步. mysql> show slave status\G *************************** 1. row ** ...

  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 transaction'问题

    OperationalError: (1205, 'Lock wait timeout exceeded; try restarting transaction') 原因很简单,太多错误,意外处理没有 ...

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

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

  7. mysql 锁 启动失败_关于mysql锁的错误Lock wait timeout exceeded; try restarting transaction 【求解】...

    2020-03-13 18:44:18 | INFO | http-nio-8085-exec-10 | com.newretail.hospital.controller.HAdviceContro ...

  8. MySQL -- Lock wait timeout exceeded; try restarting transaction参数控制

    Lock wait timeout exceeded; try restarting transaction 锁等待超时..回滚事务.. 当事务1  获得锁 start TRANSACTION upd ...

  9. 【问题解决:死锁】Lock wait timeout exceeded; try restarting transaction的问题

    执行数据删除操作时一直超时并弹出Lock wait timeout exceeded; try restarting transaction错误 解决办法 1.先查看数据库的事务隔离级别 select ...

最新文章

  1. php ajax替换数据,如何用ajax替换php函数
  2. 深度学习(三十五)——Style Transfer(2), YOLOv3, Tiny-YOLO, One-stage vs. Two-stage
  3. r语言 回归分析 分类变量_R语言 | 回归分析(二)
  4. Linux时间函数札记
  5. Maven项目添加FindBugs、PMD插件
  6. REMIX 本地环境搭建指南
  7. 鸿蒙的应用列表,图解鸿蒙列表组件ListContainer
  8. matlab常用函数通俗解释(fft2和fftshift函数设置问题等)
  9. 主席树 || 可持久化线段树 || BZOJ 3653: 谈笑风生 || Luogu P3899 [湖南集训]谈笑风生...
  10. 32768强制转换成short类型和char类型为什么是-32768和0?
  11. 中国护照可以免签的10个旅游天堂国家(地区)
  12. 什么是云效 Projex,云效Projex企业级高效研发项目管理平台
  13. 中国移动:移动互联网仍是未来发展立足点
  14. lucene ---- 黑马教程
  15. orchestrator配置参数详解-Ⅱ
  16. 动态规划-钢条切割问题
  17. 三端或者3极气体放电管和二极气体放电管的差别:主要的对地放电,不是非地极的两个极性之间放电。二极适合差模类似485通信限制AB之间的电压,当然差模也可对地
  18. 推荐系统的中的正排和倒排
  19. 静电保护元件ESD选型
  20. 传智播客视频39期 36期 达内2016年前端开发视频

热门文章

  1. python 字符串 数组 判断,Python的字符串的数组指数
  2. reportviewer控件mysql_reportviewer控件下载
  3. SpringCloud-Eureka
  4. 多线程相关-ThreadPoolExecutor
  5. tyvj 2002 扑克牌
  6. vue.js 三(数据交互)isomorphic-fetch
  7. linux中重定向学习总结
  8. union 与 union all 及其他并集操作说明
  9. 使用list和tuple
  10. Mac下搭建cocos2d 和cocos2d -x 环境