問題描述:
今天update(修改)mysql數據庫中一張表時,發現時間很長,而且會失敗。報錯:Error Code: 1205. Lock wait timeout exceeded; try restarting transaction
解決方案:
# 查看事務表
select * from information_schema.innodb_trx
在結果中發現trx_mysql_thread_id 有值 xxxx (數字)
# 運行
show processlist
結果中會有一條與xxxx(數字)對映的數據
# 在sql中執行
kill xxxx
原因分析:
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分享