【MySQL】事務沒有提交導致鎖等待Lockwaittimeoutexceeded異常的處理辦法
java.lang.Exception:
### Error updating database. Cause:java.sql.SQLException: Lock wait timeout exceeded; try restartingtransaction
### The error may involve defaultParameterMap
### The error occurred while setting parameters
### Cause: java.sql.SQLException: Lock wait timeout exceeded; tryrestarting transaction
; SQL []; Lock wait timeout exceeded; try restarting transaction;nested exception is java.sql.SQLException: Lock wait timeoutexceeded; try restarting transaction
select * from information_schema.innodb_trx之后找到了一個一直沒有提交的事務。
kill 到了對應的線程后ok了。
查看所有的進程列表:show processlist
=============================================
MySQL 5.5 -- innodb_lock_wait 鎖 等待
記得以前,當出現(xiàn):ERROR 1205(HY000): Lock wait timeout exceeded; try restartingtransaction,
要解決是一件麻煩的事情 ;
特別是當一個SQL執(zhí)行完了,但未COMMIT,后面的SQL想要執(zhí)行就是被鎖,超時結束;
DBA光從數(shù)據(jù)庫無法著手找出源頭是哪個SQL鎖住了;
有時候看看show engine innodb status , 并結合 show full processlist;能暫時解決問題;但一直不能精確定位;
在5.5中,information_schema庫中增加了三個關于鎖的表(MEMORY引擎);
innodb_trx ## 當前運行的所有事務
innodb_locks ## 當前出現(xiàn)的鎖
innodb_lock_waits ## 鎖等待的對應關系
數(shù)據(jù)庫配置文件修改:
原因:原因是你使用的InnoDB? 表類型的時候,
默認參數(shù):innodb_lock_wait_timeout設置鎖等待的時間是50s,
因為有的鎖等待超過了這個時間,所以抱錯.
你可以把這個時間加長,或者優(yōu)化存儲過程,事務避免過長時間的等待.
解決的辦法有兩個:
第一:innodb_lock_wait_timeout 鎖定等待時間改大
my.ini文件:
#innodb_lock_wait_timeout = 50
修改為
innodb_lock_wait_timeout = 500