解决Lock wait timeout exceeded; try restarting transaction问题

1 问题
mysql数据库修改某条记录的时候出现报错:
org.springframework.dao.CannotAcquireLockException: 
### Error updating database.  Cause: java.sql.SQLException: Lock wait timeout exceeded; try restarting transaction
### The error may involve com.*.dao.mapper.PhoneFlowMapper.updateByPrimaryKeySelective-Inline
### The error occurred while setting parameters

2 原因
在高并发的情况下,Spring事物造成mysql数据库事务未提交产生死锁,后续操作超时抛出异常。

mysql数据库采用InnoDB模式,默认参数:innodb_lock_wait_timeout设置锁等待的时间是50s,一旦数据库锁超过这个时间就会报错。

3 解决方法
通过以下语句查询出未提交的事务,然后kill掉事务

select * from information_schema.innodb_trx

kill 26060


————————————————
版权声明:本文为CSDN博主「汤姆猫丶」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_39403545/article/details/88688028

原文地址:https://www.cnblogs.com/yehuisir/p/14844113.html