MySQL problems

MySQL Lock Wait Timeout Exceeded: Find the Session at the Head of the Queue

2 December 2026

ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction means a statement waited innodb_lock_wait_timeout seconds, 50 by default, for a row another transaction holds. The statement that failed is the victim. The cause is the session at the head of the queue, and very often it is not running anything at all: it opened a transaction and never committed.

Ended in a deadlock instead? Paste the LATEST DETECTED DEADLOCK section into the free MySQL deadlock analyzer: dbCove AI explains the locks on both sides and gives the fix.

Who blocks whom

SELECT waiting_pid, waiting_query, wait_age,
       blocking_pid, blocking_query,
       sql_kill_blocking_connection
FROM   sys.innodb_lock_waits
ORDER  BY wait_age DESC;

When blocking_query is NULL, the blocker is idle in an open transaction. See how long it has been open, and what it holds:

SELECT t.trx_mysql_thread_id        AS session,
       t.trx_started,
       TIMEDIFF(NOW(), t.trx_started) AS open_for,
       t.trx_rows_locked, t.trx_rows_modified,
       p.user, p.host, p.command, p.time AS idle_seconds
FROM   information_schema.innodb_trx t
JOIN   information_schema.processlist p
       ON p.id = t.trx_mysql_thread_id
ORDER  BY t.trx_started;

Waiting for table metadata lock

A different queue. An ALTER TABLE, TRUNCATE or RENAME needs an exclusive metadata lock, waits for every open transaction that touched the table, and every new query on that table queues behind the DDL. One forgotten transaction and one DDL stop all traffic on the table.

SELECT object_schema, object_name,
       waiting_pid, waiting_query, waiting_query_secs,
       blocking_pid, blocking_lock_type,
       sql_kill_blocking_connection
FROM   sys.schema_table_lock_waits;

The fix, in order

  1. Find the head, not the victim. Killing the waiters frees nothing; the head keeps its locks.
  2. Ask before you kill. KILL on the head rolls its transaction back, and the rollback of a large transaction takes as long as the work it undoes, holding the locks meanwhile.
  3. For a metadata lock queue, stop the DDL first. Killing the ALTER releases everything queued behind it at once; run it again when the old transaction is gone.
  4. Fix the application. A transaction left open after an error, an ORM session that starts a transaction on read, or autocommit turned off in a pool: these are the usual heads.
  5. Bound the damage. Give DDL a short lock_wait_timeout in its own session, so it gives up instead of stopping the table: SET SESSION lock_wait_timeout = 5;. Set wait_timeout so idle connections with open transactions do not live for days.
  6. Keep the default timeout. Raising innodb_lock_wait_timeout makes victims wait longer for the same head.

See it coming

Radar Engine, the detection layer of dbCove, follows every lock chain to its head, with no agent on the server:

DetectorWhen it fires
BlockingWarning for a chain of 3 or more waiters held for 5 minutes, 10 or more waiters with a long wait, 20 or more lock wait timeouts a minute, a DDL with 5 or more queued behind it for a minute, or a head idle in a transaction for 5 minutes with 3 or more behind it. Critical when at least half of the active sessions wait.
Long transactionA transaction open for an hour or more; Warning when its session is idle.
Throughput dropStatements a second fall to a quarter of the usual while sessions are stalled behind one head.

The finding names the head: session id, user, client host, program, how long its transaction has been open, the rows it locked, the table and the kind of lock. dbCove AI reads the same chain live and proposes which session to end. It changes nothing without your click.

Questions

How do I fix "Lock wait timeout exceeded; try restarting transaction"?
Find the transaction that holds the lock with sys.innodb_lock_waits, usually a session idle in an open transaction, then commit, roll back or end it. Retrying the failed statement works only after the head is gone.

What is innodb_lock_wait_timeout?
The seconds a statement waits for a row lock before error 1205, 50 by default. It limits the wait; it does not remove the cause.

How do I find which session holds a metadata lock?
Query sys.schema_table_lock_waits. It needs the wait/lock/metadata/sql/mdl instrument, which is on by default in MySQL 8.0.

Does error 1205 roll back the transaction?
By default only the statement that timed out is rolled back, and the transaction stays open. With innodb_rollback_on_timeout = ON the whole transaction is rolled back.

Related problems

Sources