How to fix ERROR 1205: Lock wait timeout exceeded; try restarting transaction in MySQL

MySQLINTERMEDIATEHIGHUpdated Dec 23, 2025· 506 views

This error occurs when a transaction waits too long (default 50 seconds) to acquire a row lock. It happens due to uncommitted transactions holding locks, missing indexes, or high contention. You can fix it by increasing the timeout, identifying blocking sessions, or optimizing queries.

Quick fix

Fixes ERROR 1205: Lock wait timeout exceeded; try restarting transaction

SHOW FULL PROCESSLIST;
  1. Check for blocking transactions using SHOW FULL PROCESSLIST
  2. Kill the blocking connection if safe
  3. Review and optimize your application's transaction handling
  4. Add missing indexes on columns involved in locks
mysql — error
SHOW FULL PROCESSLIST;
ERROR 1205: Lock wait timeout exceeded; try restarting transaction

What this error means

ERROR 1205 indicates that an InnoDB transaction exceeded the innodb_lock_wait_timeout threshold while waiting to obtain an exclusive lock on a row. This is MySQL's safety mechanism to prevent transactions from being perpetually blocked when they cannot acquire necessary locks. By default, MySQL waits 50 seconds before timing out. The error message suggests restarting the transaction, which is the recommended action—either retry immediately or investigate why the blocking transaction hasn't completed. This error is distinct from a deadlock: a lock wait timeout rolls back only the current statement (by default), while a deadlock rolls back the entire transaction.

Typical symptoms

  • Your SQL INSERT, UPDATE, or DELETE statement fails with "ERROR 1205"
  • The error appears randomly during high database load or concurrent operations
  • Application receives "Lock wait timeout exceeded; try restarting transaction"
  • Performance degrades as transaction backlog builds up waiting for locks
  • Database connections remain open but idle for extended periods

Common causes

  1. An uncommitted transaction is holding exclusive locks on rows that other transactions need to modify
  2. Sleeping or idle processes are unnecessarily holding locks without releasing them
  3. Multiple concurrent transactions are competing for locks on the same rows (high contention)
  4. Queries lack proper indexes, forcing InnoDB to scan and lock far more rows than necessary
  5. Long-running transactions take too long to complete, blocking other operations
  6. Application code fails to commit or rollback transactions in error handlers

How to fix "ERROR 1205: Lock wait timeout exceeded; try restarting transaction"

1Check for blocking transactions using SHOW FULL PROCESSLIST

Connect to MySQL and run:

sql
SHOW FULL PROCESSLIST;

Look for processes with a long Time value (especially those in a "sleep" state with no active command). These are likely holding locks. Note the process ID (first column) of any suspicious connection.

2Kill the blocking connection if safe

Once you've identified the blocking process ID, terminate it:

sql
KILL <process_id>;

For example:

sql
KILL 42;

Make sure this connection isn't actively processing important work before killing it. Check the Command and Time columns to verify it's idle.

3Review and optimize your application's transaction handling

Ensure your application code always commits or rolls back transactions, even in exception handlers:

javascript
const connection = await mysql.createConnection(config);
try {
  await connection.query("START TRANSACTION");
  // Your query logic here
  await connection.query("COMMIT");
} catch (error) {
  await connection.query("ROLLBACK");
  throw error;
} finally {
  connection.close();
}

Enable autocommit by default to prevent accidentally holding locks:

sql
SET SESSION autocommit = 1;
4Add missing indexes on columns involved in locks

Missing indexes force InnoDB to scan entire tables, locking far more rows than necessary. Identify columns frequently used in WHERE clauses of UPDATE/DELETE statements:

sql
SHOW CREATE TABLE your_table;

Add indexes for columns in lock-heavy queries:

sql
CREATE INDEX idx_column_name ON your_table(column_name);

This reduces the number of rows locked per operation, decreasing contention.

5Increase innodb_lock_wait_timeout if timeout is too aggressive

If timeouts occur despite optimization, you can increase the timeout (default 50 seconds). This is a short-term fix; address root causes first.

Check current value:

sql
SHOW VARIABLES LIKE "innodb_lock_wait_timeout";

Increase the timeout at runtime (session-level):

sql
SET SESSION innodb_lock_wait_timeout = 100;

Or globally:

sql
SET GLOBAL innodb_lock_wait_timeout = 100;

For permanent configuration, add to /etc/my.cnf:

ini
[mysqld]
innodb_lock_wait_timeout = 100
6Enable automatic rollback on timeout (optional)

By default, MySQL rolls back only the statement that timed out, not the entire transaction (since version 5.0.13). If you prefer automatic rollback of the entire transaction, set:

sql
SET GLOBAL innodb_rollback_on_timeout = 1;

Or in /etc/my.cnf:

ini
[mysqld]
innodb_rollback_on_timeout = 1

This ensures the transaction doesn't leave behind partially committed data. However, the default behavior (statement-only rollback) is usually preferred to preserve the rest of the transaction.

Advanced notes

Lock wait timeout differs from deadlock detection. A deadlock occurs when two transactions each hold a lock the other needs (circular dependency), causing InnoDB to immediately detect and roll back one transaction. A lock wait timeout is unidirectional—one transaction simply waiting too long for a lock. On high-concurrency systems, deadlock detection (innodb_deadlock_detect) can slow performance; some systems disable it and rely on innodb_lock_wait_timeout instead.

For heavily contended workloads, consider using row-level locking hints (SELECT ... FOR UPDATE NOWAIT) to fail fast rather than wait. Monitor lock_structs and lock_rows in INFORMATION_SCHEMA.INNODB_TRX and INNODB_LOCKS for visibility into active locks and waiting transactions.

Frequently asked questions

What does "ERROR 1205: Lock wait timeout exceeded; try restarting transaction" mean?
ERROR 1205 indicates that an InnoDB transaction exceeded the innodb_lock_wait_timeout threshold while waiting to obtain an exclusive lock on a row. This is MySQL's safety mechanism to prevent transactions from being perpetually blocked when they cannot acquire necessary locks. By default, MySQL waits 50 seconds before timing out.
How do I fix "ERROR 1205: Lock wait timeout exceeded; try restarting transaction"?
This error occurs when a transaction waits too long (default 50 seconds) to acquire a row lock. It happens due to uncommitted transactions holding locks, missing indexes, or high contention. You can fix it by increasing the timeout, identifying blocking sessions, or optimizing queries.
What causes "ERROR 1205: Lock wait timeout exceeded; try restarting transaction"?
An uncommitted transaction is holding exclusive locks on rows that other transactions need to modify Sleeping or idle processes are unnecessarily holding locks without releasing them Multiple concurrent transactions are competing for locks on the same rows (high contention)
Is the "ERROR 1205: Lock wait timeout exceeded; try restarting transaction" error serious?
Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.

Official resources & further reading