MySQL error 1205 (Lock Wait Timeout Exceeded) explained: what it means, why it happens, and how to fix it — with copy-paste code examples.
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.
MySQL Error Code: 1205
Official name: Lock Wait Timeout Exceeded
Service: MySQL
Lock wait timeout exceeded; try restarting transaction
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.
SET GLOBAL innodb_lock_wait_timeout = 100;
Gives legitimately slow transactions more room while you fix the real bottleneck.
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()
}
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
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();
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.
The error names the table and the timeout; the failed statement is rolled back, the transaction can continue.
This page documents fixes for: nodejs-mysql2, python-sqlalchemy, php-pdo.
Recommendations are editorial — DB Error Reference takes no payment or affiliate fees for tool listings.
This page is based on the official MySQL documentation linked below and adds practical troubleshooting guidance on top.