Mysql 异常:Lock wait timeout exceeded; try restarting transaction;

程序莫名其妙发生异常:
Lock wait timeout exceeded; try restarting transaction; nested exception is java.sql.BatchUpdateException: Lock wait timeout exceeded; try restarting transaction

org.springframework.dao.CannotAcquireLockException: com.xxx.attack.mapper.RelationshipMapper.insert (batch index #1) failed. Cause: java.sql.BatchUpdateException: Lock wait timeout exceeded; try restarting transaction
; Lock wait timeout exceeded; try restarting transaction; nested exception is java.sql.BatchUpdateException: Lock wait timeout exceeded; try restarting transaction
	at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:267)
	at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:70)
	at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:91)
	at com.baomidou.mybatisplus.extension.toolkit.SqlHelper.executeBatch(SqlHelper.java:192)
	at com.baomidou.mybatisplus.extension.toolkit.SqlHelper.executeBatch(SqlHelper.java:217)
	at com.baomidou.mybatisplus.extension.service.impl.ServiceImpl.executeBatch(ServiceImpl.java:240)
	at com.baomidou.mybatisplus.extension.service.impl.ServiceImpl.saveBatch(ServiceImpl.java:136)
	at com.baomidou.mybatisplus.extension.service.IService.saveBatch(IService.java:73)

大致意思就是:超过锁定等待超时;尝试重新启动事务。

查了一下 发现是 MySQL出现了死锁;这里使用的是 MySQL 8.0.32 ;

使用SQL 查下:select * from information_schema.innodb_trx;

可以看到有一条锁表记录:
在这里插入图片描述
KILL 29971; KILL 后面的数字指的是 trx_mysql_thread_id 值。

可以执行上面kill命令,杀掉当前运行的事务;

猜你喜欢

转载自blog.csdn.net/linmengmeng_1314/article/details/130943537