Lab-verifiedReproduced and fixed on MySQL 8.4.13 · 2026-12-02 · container image mysql:8.4
After LOCK TABLES, a session may only use the tables it locked, and it must use them under the same names. Any other table, or the same table under an alias that was not locked, raises ERROR 1100 with the name MySQL could not find in the lock list.
Three common cases were reproduced on MySQL 8.4. The name in the message (customers, o, m) tells you what to add to LOCK TABLES.
01A table used by the query is not in LOCK TABLES
Only orders is locked, but INSERT ... SELECT also reads customers. The message names customers.
Setup
CREATE TABLE customers (id INT PRIMARY KEY, name VARCHAR(30));
CREATE TABLE orders (id INT AUTO_INCREMENT PRIMARY KEY, customer_id INT, amount INT);
INSERT INTO customers VALUES (1, 'ACME'), (2, 'GLOBEX');Query OK, 0 rows affected (0.02 sec)
Query OK, 0 rows affected (0.01 sec)
Query OK, 2 rows affected (0.01 sec)
Records: 2 Duplicates: 0 Warnings: 0LOCK TABLES orders WRITE;
INSERT INTO orders (customer_id, amount)
SELECT id, 0 FROM customers WHERE name = 'ACME';
UNLOCK TABLES;Query OK, 0 rows affected (0.00 sec)
ERROR 1100 (HY000): Table 'customers' was not locked with LOCK TABLES
Query OK, 0 rows affected (0.00 sec)SHOW TABLES;+-----------------+
| Tables_in_lab_a |
+-----------------+
| customers |
| orders |
+-----------------+
2 rows in set (0.01 sec)SHOW TABLES lists customers: the table exists, it just is not in the LOCK TABLES list.
Lock every table the statements use: LOCK TABLES orders WRITE, customers READ. The INSERT then adds 1 row.
LOCK TABLES orders WRITE, customers READ;
INSERT INTO orders (customer_id, amount)
SELECT id, 0 FROM customers WHERE name = 'ACME';
UNLOCK TABLES;
SELECT * FROM orders;Query OK, 0 rows affected (0.00 sec)
Query OK, 1 row affected (0.00 sec)
Records: 1 Duplicates: 0 Warnings: 0
Query OK, 0 rows affected (0.00 sec)
+----+-------------+--------+
| id | customer_id | amount |
+----+-------------+--------+
| 1 | 1 | 0 |
+----+-------------+--------+
1 row in set (0.00 sec)02The query uses an alias, but the table was locked without it
LOCK TABLES orders READ locks the name orders. The query refers to it as o, and MySQL reports Table 'o' was not locked.
Setup
CREATE TABLE orders (id INT PRIMARY KEY, customer VARCHAR(30), amount INT);
INSERT INTO orders VALUES (1, 'ACME', 120000), (2, 'GLOBEX', 45000);Query OK, 0 rows affected (0.02 sec)
Query OK, 2 rows affected (0.00 sec)
Records: 2 Duplicates: 0 Warnings: 0LOCK TABLES orders READ;
SELECT o.id, o.amount FROM orders o WHERE o.amount > 50000;
UNLOCK TABLES;Query OK, 0 rows affected (0.00 sec)
ERROR 1100 (HY000): Table 'o' was not locked with LOCK TABLES
Query OK, 0 rows affected (0.00 sec)SHOW TABLES;+-----------------+
| Tables_in_lab_a |
+-----------------+
| orders |
+-----------------+
1 row in set (0.00 sec)Lock it under the alias the query uses: LOCK TABLES orders AS o READ. The SELECT returns the row.
LOCK TABLES orders AS o READ;
SELECT o.id, o.amount FROM orders o WHERE o.amount > 50000;
UNLOCK TABLES;Query OK, 0 rows affected (0.00 sec)
+----+--------+
| id | amount |
+----+--------+
| 1 | 120000 |
+----+--------+
1 row in set (0.00 sec)
Query OK, 0 rows affected (0.00 sec)03Self-join: the same table under two aliases, only one locked
The query joins employees e with employees m. Only alias e is locked, so m fails.
Setup
CREATE TABLE employees (id INT PRIMARY KEY, name VARCHAR(30), manager_id INT);
INSERT INTO employees VALUES (1, 'Kim', NULL), (2, 'Lee', 1), (3, 'Park', 1);Query OK, 0 rows affected (0.02 sec)
Query OK, 3 rows affected (0.00 sec)
Records: 3 Duplicates: 0 Warnings: 0LOCK TABLES employees AS e READ;
SELECT e.name, m.name AS manager
FROM employees e JOIN employees m ON m.id = e.manager_id;
UNLOCK TABLES;Query OK, 0 rows affected (0.00 sec)
ERROR 1100 (HY000): Table 'm' was not locked with LOCK TABLES
Query OK, 0 rows affected (0.00 sec)SHOW TABLES;+-----------------+
| Tables_in_lab_a |
+-----------------+
| employees |
+-----------------+
1 row in set (0.00 sec)Lock the table once per alias: LOCK TABLES employees AS e READ, employees AS m READ. The join returns 2 rows.
LOCK TABLES employees AS e READ, employees AS m READ;
SELECT e.name, m.name AS manager
FROM employees e JOIN employees m ON m.id = e.manager_id;
UNLOCK TABLES;Query OK, 0 rows affected (0.00 sec)
+------+---------+
| name | manager |
+------+---------+
| Lee | Kim |
| Park | Kim |
+------+---------+
2 rows in set (0.00 sec)
Query OK, 0 rows affected (0.00 sec)FAQ
How do I fix MySQL ERROR 1100 Table was not locked with LOCK TABLES?
Add the table named in the message to the same LOCK TABLES statement. If the name is an alias, lock it as table AS alias.
Why does an alias cause ERROR 1100?
Under LOCK TABLES, MySQL checks names exactly as the query uses them. If the query says orders o, lock orders AS o.
How do I lock a table used twice in a self-join?
Lock it once for each alias: LOCK TABLES employees AS e READ, employees AS m READ.
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