---
title: "Lock wait timeout exceeded"
author: "e_e"
date: "2023-10-12T14:47:50Z"
tags: []
categories: ["编程语言"]
slug: "lock-wait-timeout-exceeded"
draft: false
lastmod: "2023-10-12T14:54:53Z"
id: 2539511
url: "https://e-e.iteye.com/blog/2539511"
---

错误信息：

 

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.数据归档。