问题描述:
今天update(修改)mysql数据库中一张表时,发现时间很长,而且会失败。报错:Error Code: 1205. Lock wait timeout exceeded; try restarting transaction
解决方案:
# 查看事务表
select * from information_schema.innodb_trx
在结果中发现trx_mysql_thread_id 有值 xxxx (数字)
# 运行
结果中会有一条与xxxx(数字)对映的数据
# 在sql中执行
原因分析:
mysql的innoDB存储引擎是支持事务的,事务开启后没有被主动commit。导致该资源被长期占用,其他事务在抢占该资源时,因上一个事务的锁而导致抢占失败!因此出现Lock wait timeout exceeded
MySQL 5.5 innodb_lock_wait 锁等待:
在mysql 5.5 中,information_schema 库中增加了三个关于锁的表(MEMORY引擎);
innodb_trx ## 当前运行的所有事物
innodb_locks ## 当前出现的锁
innodb_lock_waits ##锁等待的对应关系
对应表的结构:



参考文章一:https://blog.csdn.net/wyyl1/article/details/80517139
参考文章二:http://blog.sina.com.cn/s/blog_6bb63c9e0100s7cb.html
参考文章三:https://my.oschina.net/quanzhong/blog/222091
如有更详细的资料,望帅哥美女,CV分享 |