MySQL

ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction: causes and fix

Find the blocking transaction behind MySQL error 1205, kill or commit it, and stop the lock wait timeout from coming back. Commands for Ubuntu and RHEL.

ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction

In short

MySQL error 1205 comes from the InnoDB storage engine. One transaction waited for a row lock held by another transaction and gave up after innodb_lock_wait_timeout seconds (50 by default). MySQL rolls back the waiting statement, not the one holding the lock. The blocker is usually a transaction left open, a long-running write, or a batch job.

Likely causes

  • •A transaction was left open. An application ran BEGIN or an update and never committed, often after an error path or a stuck worker. In SHOW ENGINE INNODB STATUS the blocker shows a long transaction time, and in information_schema.innodb_trx its trx_state is RUNNING while its connection sits idle in SHOW PROCESSLIST (Command: Sleep).
  • •A long-running batch update or delete. A large UPDATE, DELETE or import locks many rows for minutes. Other sessions that touch the same rows time out. Check SHOW FULL PROCESSLIST for a query with a high Time value against the same table.
  • •Missing index makes a write lock too many rows. Without a usable index on the WHERE column, InnoDB scans and locks far more rows than you meant to change. Run EXPLAIN on the slow UPDATE or DELETE. A type of ALL means a full scan.
  • •Two jobs update the same rows in conflicting order. Queue workers, cron jobs or web requests that touch the same hot rows block each other. The error appears in bursts at the same time each day or under load. If MySQL instead reports error 1213 (deadlock), that is a different problem.
  • •A DDL statement or backup holding a metadata lock. ALTER TABLE, or a dump taken without --single-transaction, can block writes. SHOW PROCESSLIST shows states such as Waiting for table metadata lock. Note that a metadata lock wait is governed by lock_wait_timeout, not innodb_lock_wait_timeout.
  • •Timeout is too low for the workload. Legitimate transactions simply take longer than the timeout. You see the error with no obvious blocker and with short, steady lock holds that add up under concurrency. Fix the slow queries first and raise the timeout only as a last step.

How to fix it

  1. 1. Find who is blocking

    While the error is happening, list the waiting and blocking transactions. This uses the sys schema, which ships with MySQL 5.7.7 and later. The columns selected here exist in both 5.7 and 8.0.

    mysql -u root -p -e "SELECT wait_started, wait_age, waiting_pid, waiting_query, blocking_pid, blocking_query FROM sys.innodb_lock_waits\G"
  2. 2. Look at the blocker's full transaction

    Use the blocking_pid from step 1. A transaction that is old and idle is the usual culprit. The first query shows how long each open transaction has been running.

    mysql -u root -p -e "SELECT trx_id, trx_state, trx_started, trx_mysql_thread_id, trx_rows_locked, trx_query FROM information_schema.innodb_trx ORDER BY trx_started"
    mysql -u root -p -e "SHOW FULL PROCESSLIST"
  3. 3. Release the lock

    Prefer to let the blocker commit or finish. If it is stuck, kill its connection. Warning: KILL rolls back that transaction, and any uncommitted work in it is lost. A large rollback can itself take a long time, so confirm what the session is doing first.

    mysql -u root -p -e "KILL 12345"
  4. 4. Fix the application path that leaves transactions open

    Make sure every code path commits or rolls back, including error handlers. Keep transactions short, and do slow work such as HTTP calls or file processing outside them. Retry the whole transaction when you get error 1205, as the message suggests.

  5. 5. Add the missing index and break up big writes

    Run EXPLAIN on the slow UPDATE or DELETE and add an index on the filtered column. Warning: adding an index to a large table can be slow and load the server, so do it in a quiet window. Split big batch jobs into chunks of a few thousand rows, committing after each chunk.

    mysql -u root -p -e "EXPLAIN UPDATE orders SET status = 'done' WHERE customer_id = 42"
  6. 6. Check the current timeout

    The default is 50 seconds. Check what your server uses before changing anything.

    mysql -u root -p -e "SHOW VARIABLES LIKE 'innodb_lock_wait_timeout'"
  7. 7. Raise the timeout only if needed

    Set it for one session first, for example for a batch job. To change the global value for new connections, use SET GLOBAL, and add it to the config file to survive a restart. The file is usually /etc/mysql/mysql.conf.d/mysqld.cnf on Ubuntu and Debian, and /etc/my.cnf or /etc/my.cnf.d/ on RHEL-family systems. A higher value hides the problem and keeps locks held longer, so treat it as a stopgap. Changing the config file takes effect only after a MySQL restart, which drops connections, so plan for that.

    mysql -u root -p -e "SET GLOBAL innodb_lock_wait_timeout = 120"
    
    # in the [mysqld] section of your config file:
    # innodb_lock_wait_timeout = 120

Confirm it is fixed

Re-run the statement or job that failed. Then confirm nothing is waiting on a lock and no old transaction is open. Good output is a waiting count of 0 from the first query, and no rows at all from the second query, which lists only transactions that started more than 60 seconds ago.

mysql -u root -p -e "SELECT COUNT(*) AS waiting FROM sys.innodb_lock_waits; SELECT trx_id, trx_started, trx_state FROM information_schema.innodb_trx WHERE trx_started < NOW() - INTERVAL 60 SECOND ORDER BY trx_started"

How Opservo catches it early

The Opservo agent lists MySQL queries that have been running for more than 5 seconds, which is often how a lock holder shows up, and it flags a server that is almost out of connections as waiting sessions pile up. It also groups repeated log lines into patterns and raises a recurring error finding with a plain-English AI summary when an error keeps coming back.

Last updated 2026-11-30.

FAQ

Related questions

Does error 1205 roll back my whole transaction?+

By default, only the statement that timed out is rolled back, and the transaction stays open. Your application should roll back the whole transaction and retry it, or it may commit partial work. The innodb_rollback_on_timeout option, set at server startup, changes this to roll back the entire transaction.

What is the difference between error 1205 and error 1213?+

Error 1205 means a transaction waited too long for a lock. Error 1213 means MySQL detected a deadlock, where two transactions wait on each other, and rolled one back at once. Both are fixed by shorter transactions and consistent update order.

Should I just increase innodb_lock_wait_timeout?+

Only as a temporary measure. A higher value makes requests wait longer and can pile up connections. Find and fix the transaction holding the lock instead.