mysql Lock wait timeout exceeded; try restarting transaction解决方案
在测试程序时,打的断点怎么都跳不进去,console一直报 “Lock wait timeout exceeded;try restarting transaction”t 这个文件的内容就是show full processlist所有session.这里只需要kill block的sql即可,使用grep + awk即可解决。此处是在对list做更新动作,因此存在锁表的风险。– 2022年11
·
背景
在测试程序时,打的断点怎么都跳不进去,console一直报 “Lock wait timeout exceeded; try restarting transaction”
org.springframework.dao.CannotAcquireLockException: could not execute statement; SQL [n/a]; nested exception is org.hibernate.exception.LockAcquisitionException: could not execute statement。
从字面意思得知,是表锁了所以进不到断点里面,查看代码发现:

此处是在对list做更新动作,因此存在锁表的风险。
Mysql 查看锁:
select * from information_schema.innodb_trx ## 当前运行的所有事务
select * from information_schema.innodb_locks ##当前出现的锁
select * from information_schema.innodb_lock_waits ## 锁等待的对应关系。
如何释放锁?
1、执行show full processlist

2、kill $id
这里只需要kill block的sql即可,使用grep + awk即可解决。
– 2022年11月22日13:18:33
t 这个文件的内容就是show full processlist所有session.
执行如下脚本即可释放掉lock。
grep 'updating' t | awk '{print $1}' | xargs -I GG echo "kill GG;" | bash
为什么会出现锁?
更多推荐



所有评论(0)