Lock wait timeout exceeded
错误信息:
org.springframework.dao.CannotAcquireLockException: ### Error updating database. Cause: com.mysql.cj.jdbc.exceptions.MySQLTransactionRollbackException: Lockwaittimeoutexceeded; try restarting transaction
原因:表的某条记录更增操作可能在另外一个大的事务里被锁,锁的时间超过了数据库指定时间(如下图:innodb_lock_wait_timeout=10秒),导致此处获取不到这条数据的锁而报错。
优化方法:
1.大批量更增执行改成小批量。
2.大事务拆分。
3.数据归档。