Skip to content

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

Key points

  • Error 1205 is a timeout, not a deadlock.
  • Only the statement rolls back by default, not the transaction.
  • Unindexed UPDATEs lock far more rows than they change.
  • Find the blocker before raising any limit.

What it means

InnoDB locks rows that are changed, and another transaction wanting the same row waits. After innodb_lock_wait_timeout, 50 seconds by default, it fails with error 1205. The default rolls back only that one statement, so an application that continues and commits may save partial work.

Common causes

  • Long transactions that do slow work while holding locks.
  • UPDATE or DELETE on an unindexed column, locking many rows as it scans.
  • Large batch jobs in one transaction.
  • An abandoned session that never committed.

Diagnose it

MySQL 8 exposes this through the sys schema: it names waiting and blocking sessions directly.

bash
-- 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.

Frequently asked questions

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.

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.