Troubleshooting guide
MySQL "Lock wait timeout exceeded": how to fix it
A transaction waited longer than allowed for a row lock. The statement that failed is the victim, so look for the transaction that was holding the lock.
3 min read10 sectionsUpdated
On this page
Diagnose it
MySQL 8 exposes this through the sys schema: it names waiting and blocking sessions directly.
-- Who waits for whom
SELECT wait_age, locked_table, waiting_query, blocking_pid, blocking_query, sql_kill_blocking_connection
FROM sys.innodb_lock_waits;
-- Oldest open transactions
SELECT trx_id, trx_started, trx_mysql_thread_id, trx_rows_locked, LEFT(trx_query, 80)
FROM information_schema.innodb_trx ORDER BY trx_started LIMIT 10;
-- Does the update use an index?
EXPLAIN UPDATE orders SET status = 'x' WHERE customer_ref = 'abc';Fixes
Index the columns in WHERE clauses of writes. Keep transactions short and do no network calls inside them. Break batch jobs into small chunks committed separately. End a stuck session with KILL <thread_id>;. Retry 1205 in application code, and roll back the whole transaction, or set innodb_rollback_on_timeout so that partial work cannot be committed.
Why raising the timeout rarely helps
Increasing innodb_lock_wait_timeout makes requests wait longer before failing, tying up connections and threads in the meantime. During a real incident, that can exhaust the connection limit and take down far more than the one table involved. For interactive traffic a shorter timeout is often better. MySQL 8's NOWAIT and SKIP LOCKED options are useful for job-queue style workloads, where a worker can simply move on to the next available row instead of waiting.
Catch it automatically
Count 1205 errors in your logs and watch the longest-running transaction in MySQL monitoring. A trace showing many requests stuck on one UPDATE in APM tells you which table to look at.
What is the difference between a deadlock and a lock wait timeout?
A deadlock is a cycle that InnoDB detects and breaks at once. A lock wait timeout is a plain wait that lasted too long.
Should I retry after error 1205?
Yes, with backoff, after rolling back the transaction.
Does this affect SELECT?
Plain reads use snapshots and do not wait, but SELECT FOR UPDATE does.
Related reading
- MySQL server has gone away: causes and how to fix it: Fix MySQL error 2006 server has gone away: idle timeouts, oversized packets, server restarts and connection pools holding connections that have died.
- 408 Request Timeout: causes and how to fix it: Understand 408 Request Timeout: slow client uploads, idle keep-alive connections and proxy settings, and how it differs from a 504 Gateway Timeout.
- PostgreSQL idle in transaction: find and fix it: Find and fix PostgreSQL idle in transaction sessions: why they block vacuum and hold locks, which application patterns cause them and which timeout to set.
- PHP maximum execution time exceeded: how to fix it: Fix PHP Maximum execution time of 30 seconds exceeded: why external waits may not count, which timeouts line up with Nginx, and how to move long work away.
- WordPress "Error establishing a database connection": fix: Fix WordPress Error establishing a database connection: check wp-config credentials, MySQL status, connection limits and damaged tables with safe commands.
- 504 Gateway Timeout: causes and fixes: What causes 504 Gateway Timeout errors, how timeouts stack across CDN, load balancer and Nginx, and how to find and fix the slow request.
Watch your own site and services with VitalRix
Uptime checks, APM, logs, real-user monitoring, alerts and status pages in one place. Every product has a free tier and no credit card is needed.