MySQL Error 1205: Lock Wait Timeout Exceeded

MySQL error 1205 (Lock Wait Timeout Exceeded) explained: what it means, why it happens, and how to fix it — with copy-paste code examples.

MySQL Error Code 1205 MySQL Last verified 2026-08-19

Quick Answer

The error names the table and the timeout; the failed statement is rolled back, the transaction can continue. If that does not apply, inspect current locks: `SHOW ENGINE INNODB STATUS;` under 'LATEST DETECTED LOCK' / 'TRANSACTIONS' — the full checklist is below.

Error Code

MySQL Error Code: 1205
Official name: Lock Wait Timeout Exceeded
Service: MySQL

What does this error mean?

Lock wait timeout exceeded; try restarting transaction

Common Causes

How to Fix

  1. The error names the table and the timeout; the failed statement is rolled back, the transaction can continue
  2. Inspect current locks: `SHOW ENGINE INNODB STATUS;` under 'LATEST DETECTED LOCK' / 'TRANSACTIONS'
  3. Commit or roll back transactions quickly; never leave a transaction open across user requests
  4. Add indexes so UPDATE/DELETE lock only the needed rows, not a full table scan
  5. Raise innodb_lock_wait_timeout if legitimate long waits exist: SET GLOBAL innodb_lock_wait_timeout = 100;
  6. Split huge bulk updates into batches to shorten individual lock holds

Code Examples

See who holds the lock sql
SHOW ENGINE INNODB STATUS;
-- look under TRANSACTIONS for the oldest transaction holding locks

Reveals the blocking transaction so you can kill or wait for it.

Raise the timeout (temporary) sql
SET GLOBAL innodb_lock_wait_timeout = 100;

Gives legitimately slow transactions more room while you fix the real bottleneck.

Framework-Specific Fixes

nodejs-mysql2

Use short transactions with automatic rollback on error; release the connection in finally.

const conn = await pool.getConnection()
try {
  await conn.beginTransaction()
  await conn.query('UPDATE inventory SET qty = qty - ? WHERE id = ?', [1, itemId])
  await conn.commit()
} catch (e) {
  await conn.rollback()
  throw e
} finally {
  conn.release()
}
python-sqlalchemy

Commit promptly and retry the transaction on lock wait timeout.

from sqlalchemy.exc import OperationalError
for attempt in range(3):
    try:
        with session.begin():
            update_inventory(session)
        break
    except OperationalError as e:
        if e.orig.args[0] != 1205: raise
php-pdo

Keep the transaction body minimal: only the statements that must be atomic.

$pdo->beginTransaction();
// do the smallest amount of work here, commit fast
$pdo->commit();

You Might Also Like

Frequently Asked Questions

Why am I seeing MySQL error 1205?

Most often this happens when a transaction held a row lock longer than innodb_lock_wait_timeout (default 50 seconds), or when a long-running transaction (missing commit/rollback, slow query) blocking others.

How do I fix MySQL error 1205?

The error names the table and the timeout; the failed statement is rolled back, the transaction can continue.

Which frameworks have documented fixes for error 1205?

This page documents fixes for: nodejs-mysql2, python-sqlalchemy, php-pdo.

Official Sources

This page is based on the official MySQL documentation linked below and adds practical troubleshooting guidance on top.