MySQL 8.4Lab-verified · 2026-12-01

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

Another transaction holds a lock on the row you need and did not finish within innodb_lock_wait_timeout.

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

Jump to a cause

  1. 01Another session updated the row and has not committed
  2. 02The WHERE column has no index, so UPDATE locks rows it does not change
  3. 03SELECT ... FOR UPDATE keeps the row locked until the transaction ends
  4. 04FOR UPDATE on a row that does not exist locks the gap, so INSERTs wait

Lab-verifiedReproduced and fixed on MySQL 8.4.13 · 2026-12-01 · container image mysql:8.4

InnoDB makes a statement wait when another transaction holds a lock on a row it needs. If the lock is not released within innodb_lock_wait_timeout seconds, the waiting statement fails with ERROR 1205. In these experiments session B set the timeout to 5 seconds so the error appears quickly.

The statement that fails is the waiting one, not the one holding the lock. So the fix is almost always on the other side: find the transaction that holds the lock and make it finish sooner, or make it lock fewer rows.

01Another session updated the row and has not committed

Session A ran START TRANSACTION and updated item 1 without committing. Session B's UPDATE on the same row waited, and after 5 seconds it failed with ERROR 1205.

While B was waiting, sys.innodb_lock_waits (run as root) showed who was blocking whom: waiting_pid was B and blocking_pid was A, and blocking_query was NULL because A was not running anything, just sitting in an open transaction. It also prints a ready-made KILL <blocking_pid> statement (sql_kill_blocking_connection).

In the retry, A ran COMMIT while B was waiting. B's UPDATE finished right away (2.31 sec including the wait) and qty became 97.

Setup
Setuprun as lab_a
CREATE TABLE stock (item_id INT PRIMARY KEY, qty INT);
INSERT INTO stock VALUES (1, 100), (2, 50);
OUTPUT
Query OK, 0 rows affected (0.02 sec)

Query OK, 2 rows affected (0.00 sec)
Records: 2  Duplicates: 0  Warnings: 0
Reproduce3 sessions open at the same time (A, B, C), run in this order
Session Arun as lab_a
START TRANSACTION;
UPDATE stock SET qty = qty - 1 WHERE item_id = 1;
OUTPUT
Query OK, 0 rows affected (0.00 sec)

Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0
Session Brun as lab_a
SET innodb_lock_wait_timeout = 5;
OUTPUT
Query OK, 0 rows affected (0.00 sec)
Session Brun as lab_a⏳ Waiting for the lock…
UPDATE stock SET qty = qty - 2 WHERE item_id = 1;
Session C · Checkrun as root
SELECT waiting_pid, waiting_query, blocking_pid, blocking_query, sql_kill_blocking_connection
FROM sys.innodb_lock_waits\G
OUTPUT
*************************** 1. row ***************************
                 waiting_pid: 15
               waiting_query: UPDATE stock SET qty = qty - 2 WHERE item_id = 1
                blocking_pid: 14
              blocking_query: NULL
sql_kill_blocking_connection: KILL 14
1 row in set (0.01 sec)
Session B: the waiting statement finishesrun as lab_a
OUTPUT
ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction

A NULL blocking_query usually means an application or a SQL client left a transaction open. Commit or roll it back; killing the connection rolls back its changes.

After the fix3 sessions open at the same time (A, B, C), run in this order
Session Arun as lab_a
START TRANSACTION;
UPDATE stock SET qty = qty - 1 WHERE item_id = 1;
OUTPUT
Query OK, 0 rows affected (0.00 sec)

Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0
Session Brun as lab_a
SET innodb_lock_wait_timeout = 5;
OUTPUT
Query OK, 0 rows affected (0.00 sec)
Session Brun as lab_a⏳ Waiting for the lock…
UPDATE stock SET qty = qty - 2 WHERE item_id = 1;
Session A · Fixrun as lab_a
COMMIT;
OUTPUT
Query OK, 0 rows affected (0.00 sec)
Session B: the waiting statement finishesrun as lab_a
OUTPUT
Query OK, 1 row affected (2.31 sec)
Rows matched: 1  Changed: 1  Warnings: 0
Session C · Checkrun as lab_a
SELECT item_id, qty FROM stock;
OUTPUT
+---------+------+
| item_id | qty  |
+---------+------+
|       1 |   97 |
|       2 |   50 |
+---------+------+
2 rows in set (0.00 sec)

02The WHERE column has no index, so UPDATE locks rows it does not change

orders.customer has no index. Session A updated customer = 'kim' (not committed) and session B updated customer = 'lee', a different row. B still waited and got ERROR 1205.

Without an index InnoDB has to scan the whole table and lock every row it reads, so A's UPDATE also locked lee's row. After CREATE INDEX orders_customer_ix ON orders (customer) the same two UPDATEs ran side by side: B finished immediately while A was still open, and both committed.

Setup
Setuprun as lab_a
CREATE TABLE orders (order_id INT PRIMARY KEY, customer VARCHAR(20), status VARCHAR(10));
INSERT INTO orders VALUES (1, 'kim', 'NEW'), (2, 'lee', 'NEW'), (3, 'park', 'NEW');
OUTPUT
Query OK, 0 rows affected (0.01 sec)

Query OK, 3 rows affected (0.01 sec)
Records: 3  Duplicates: 0  Warnings: 0
Reproduce2 sessions open at the same time (A, B), run in this order
Session Arun as lab_a
START TRANSACTION;
UPDATE orders SET status = 'PAID' WHERE customer = 'kim';
OUTPUT
Query OK, 0 rows affected (0.00 sec)

Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0
Session Brun as lab_a
SET innodb_lock_wait_timeout = 5;
OUTPUT
Query OK, 0 rows affected (0.00 sec)
Session Brun as lab_a⏳ Waiting for the lock…
UPDATE orders SET status = 'PAID' WHERE customer = 'lee';
Session B: the waiting statement finishesrun as lab_a
OUTPUT
ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction
Fixrun as lab_a
CREATE INDEX orders_customer_ix ON orders (customer);
OUTPUT
Query OK, 0 rows affected (0.02 sec)
Records: 0  Duplicates: 0  Warnings: 0

If two sessions touch different rows and still block each other, check the WHERE columns of the UPDATE or DELETE with EXPLAIN.

After the fix2 sessions open at the same time (A, B), run in this order
Session Arun as lab_a
START TRANSACTION;
UPDATE orders SET status = 'PAID' WHERE customer = 'kim';
OUTPUT
Query OK, 0 rows affected (0.00 sec)

Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0
Session Brun as lab_a
SET innodb_lock_wait_timeout = 5;
OUTPUT
Query OK, 0 rows affected (0.00 sec)
Session Brun as lab_a
UPDATE orders SET status = 'PAID' WHERE customer = 'lee';
OUTPUT
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0
Session Arun as lab_a
COMMIT;
OUTPUT
Query OK, 0 rows affected (0.00 sec)
Session Brun as lab_a
COMMIT;
OUTPUT
Query OK, 0 rows affected (0.00 sec)

03SELECT ... FOR UPDATE keeps the row locked until the transaction ends

A numbering table: session A read the next invoice number with SELECT ... FOR UPDATE and did not finish its transaction. Session B ran the same FOR UPDATE query and timed out with ERROR 1205.

In the retry, A incremented the number and ran COMMIT. B's waiting FOR UPDATE then returned at once and read 2, the value A had just committed.

Setup
Setuprun as lab_a
CREATE TABLE seq_no (name VARCHAR(20) PRIMARY KEY, next_no INT);
INSERT INTO seq_no VALUES ('INVOICE', 1);
OUTPUT
Query OK, 0 rows affected (0.02 sec)

Query OK, 1 row affected (0.00 sec)
Reproduce2 sessions open at the same time (A, B), run in this order
Session Arun as lab_a
START TRANSACTION;
SELECT next_no FROM seq_no WHERE name = 'INVOICE' FOR UPDATE;
OUTPUT
Query OK, 0 rows affected (0.01 sec)

+---------+
| next_no |
+---------+
|       1 |
+---------+
1 row in set (0.00 sec)
Session Brun as lab_a
SET innodb_lock_wait_timeout = 5;
OUTPUT
Query OK, 0 rows affected (0.00 sec)
Session Brun as lab_a⏳ Waiting for the lock…
START TRANSACTION;
SELECT next_no FROM seq_no WHERE name = 'INVOICE' FOR UPDATE;
Session B: the waiting statement finishesrun as lab_a
OUTPUT
Query OK, 0 rows affected (0.00 sec)

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

Keep the work between FOR UPDATE and COMMIT short. Do not wait for user input or slow external calls while the row is locked.

After the fix2 sessions open at the same time (A, B), run in this order
Session Arun as lab_a
START TRANSACTION;
SELECT next_no FROM seq_no WHERE name = 'INVOICE' FOR UPDATE;
UPDATE seq_no SET next_no = next_no + 1 WHERE name = 'INVOICE';
OUTPUT
Query OK, 0 rows affected (0.00 sec)

+---------+
| next_no |
+---------+
|       1 |
+---------+
1 row in set (0.00 sec)

Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0
Session Brun as lab_a
SET innodb_lock_wait_timeout = 5;
OUTPUT
Query OK, 0 rows affected (0.00 sec)
Session Brun as lab_a⏳ Waiting for the lock…
START TRANSACTION;
SELECT next_no FROM seq_no WHERE name = 'INVOICE' FOR UPDATE;
Session A · Fixrun as lab_a
COMMIT;
OUTPUT
Query OK, 0 rows affected (0.00 sec)
Session B: the waiting statement finishesrun as lab_a
OUTPUT
Query OK, 0 rows affected (0.00 sec)

+---------+
| next_no |
+---------+
|       2 |
+---------+
1 row in set (2.30 sec)
Session Brun as lab_a
COMMIT;
OUTPUT
Query OK, 0 rows affected (0.00 sec)

04FOR UPDATE on a row that does not exist locks the gap, so INSERTs wait

Room 101 has bookings only on Dec 1 and Dec 10. Session A checked "is Dec 5 booked?" with SELECT ... FOR UPDATE and got Empty set. No row was locked, yet when session B inserted a booking for a different day, Dec 7, it waited and failed with ERROR 1205.

Under the default isolation level (REPEATABLE READ), a FOR UPDATE that finds nothing still locks the place where the value would go: the gap in the index between Dec 1 and Dec 10. An INSERT into that gap waits, even for a different date.

In the retry both sessions ran SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED. A ran the same FOR UPDATE, got an empty result and kept its transaction open, but B's Dec 7 INSERT and COMMIT finished immediately and A then saw 3 rows.

Setup
Setuprun as lab_a
CREATE TABLE bookings (id INT AUTO_INCREMENT PRIMARY KEY, room_id INT NOT NULL, day DATE NOT NULL, KEY bookings_room_day_ix (room_id, day));
INSERT INTO bookings (room_id, day) VALUES (101, '2026-12-01'), (101, '2026-12-10');
OUTPUT
Query OK, 0 rows affected (0.01 sec)

Query OK, 2 rows affected (0.00 sec)
Records: 2  Duplicates: 0  Warnings: 0
Reproduce2 sessions open at the same time (A, B), run in this order
Session Arun as lab_a
START TRANSACTION;
SELECT id FROM bookings WHERE room_id = 101 AND day = '2026-12-05' FOR UPDATE;
OUTPUT
Query OK, 0 rows affected (0.00 sec)

Empty set (0.00 sec)
Session Brun as lab_a
SET innodb_lock_wait_timeout = 5;
OUTPUT
Query OK, 0 rows affected (0.00 sec)
Session Brun as lab_a⏳ Waiting for the lock…
START TRANSACTION;
INSERT INTO bookings (room_id, day) VALUES (101, '2026-12-07');
Session B: the waiting statement finishesrun as lab_a
OUTPUT
Query OK, 0 rows affected (0.00 sec)

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

READ COMMITTED does not lock empty ranges. If your "insert if missing" logic relied on the FOR UPDATE gap lock, it will no longer stop the same value being inserted twice, so you need something else such as a unique key.

After the fix2 sessions open at the same time (A, B), run in this order
Session A · Fixrun as lab_a
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
OUTPUT
Query OK, 0 rows affected (0.00 sec)
Session Arun as lab_a
START TRANSACTION;
SELECT id FROM bookings WHERE room_id = 101 AND day = '2026-12-05' FOR UPDATE;
OUTPUT
Query OK, 0 rows affected (0.00 sec)

Empty set (0.00 sec)
Session B · Fixrun as lab_a
SET innodb_lock_wait_timeout = 5;
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
OUTPUT
Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)
Session Brun as lab_a
START TRANSACTION;
INSERT INTO bookings (room_id, day) VALUES (101, '2026-12-07');
COMMIT;
OUTPUT
Query OK, 0 rows affected (0.00 sec)

Query OK, 1 row affected (0.00 sec)

Query OK, 0 rows affected (0.01 sec)
Session Arun as lab_a
SELECT room_id, day FROM bookings WHERE room_id = 101 ORDER BY day;
COMMIT;
OUTPUT
+---------+------------+
| room_id | day        |
+---------+------------+
|     101 | 2026-12-01 |
|     101 | 2026-12-07 |
|     101 | 2026-12-10 |
+---------+------------+
3 rows in set (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

FAQ

How do I find which session is causing lock wait timeout exceeded?

While the statement is still waiting, query sys.innodb_lock_waits as an administrator. It shows the waiting and blocking connection ids, the waiting query, and a sql_kill_blocking_connection column with a ready-made KILL statement. In the first experiment on this page the blocker had blocking_query NULL because it was an idle open transaction.

Should I just increase innodb_lock_wait_timeout?

It only makes the statement wait longer. In every experiment here the wait ended as soon as the other transaction committed, so the real fix is to shorten or fix the transaction that holds the lock.

Why does UPDATE on a different row wait for a lock?

Check for a missing index on the WHERE column. Without it InnoDB locks every row it scans. On this page an UPDATE for customer 'lee' waited for an UPDATE for 'kim' until an index on customer was added.

Why does INSERT get lock wait timeout when SELECT FOR UPDATE returned no rows?

Under REPEATABLE READ, SELECT ... FOR UPDATE locks the index gap where the value would go even if no row is found. In this page an empty FOR UPDATE for Dec 5 made an INSERT for Dec 7 wait until ERROR 1205; with both sessions on READ COMMITTED the INSERT went through at once.

Is ERROR 1205 the same as a deadlock?

No. 1205 means the statement waited too long; the other transaction could still finish normally. A deadlock is ERROR 1213, where two transactions wait for each other and MySQL rolls one back immediately.

How we verify

Each scenario starts from fresh database users. A script runs the setup, confirms the exact error code, applies the fix and runs the statement again. The output shown is what the database printed, saved by the script.

lab_a and lab_b are ordinary users created for the test, each with full rights on a database of the same name (its default database); root is the administrator. MySQL 8.4.13