Common SQL Errors

MySQL Error 1100: ER_TABLE_NOT_LOCKED - How to Diagnose and Fix

Galaxy Team
August 5, 2025

MySQL throws ER_TABLE_NOT_LOCKED (SQLSTATE HY000) when a session tries to read or write a table that is not locked after a LOCK TABLES statement was issued in the same connection.

Sign up for the latest in common SQL errors from the Galaxy Team!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

What is MySQL error 1100 ER_TABLE_NOT_LOCKED?

MySQL Error 1100: ER_TABLE_NOT_LOCKED occurs when a query touches a table that has not been explicitly locked after issuing LOCK TABLES. Lock every referenced table or end the lock session with UNLOCK TABLES to resolve the issue.

Error Highlights

Typical Error Message

Table '%s' was not locked with LOCK TABLES

Error Type

Lock Error

Language

MySQL

Symbol

ER_TABLE_NOT_LOCKED

Error Code

1100

SQL State

Explanation

Table of Contents

What does “Table '%s' was not locked with LOCK TABLES” mean?

Error 1100 (ER_TABLE_NOT_LOCKED) signals that the current connection entered locked-tables mode by running LOCK TABLES, but the following statement references a table that was not included in the lock list. In this mode MySQL enforces manual locks to guarantee consistency.

The server blocks the statement to avoid reading or writing data without the expected lock, which could break transactional guarantees or return inconsistent results.

The error always appears within the same session that executed LOCK TABLES.

.

What Causes This Error?

Issuing SELECT ... FOR UPDATE, INSERT, UPDATE, or DELETE on a table that was not named in the preceding LOCK TABLES clause immediately triggers the error.

Mixing privileged statements such as ALTER TABLE or CREATE TEMPORARY TABLE after LOCK TABLES without adding them to the lock list also causes error 1100.

How to Fix MySQL Error 1100

Always lock every table you plan to touch. Add missing tables to the LOCK TABLES statement with the correct read or write lock type, then retry the query.

If you no longer need explicit locks, end locked-tables mode with UNLOCK TABLES or by closing the connection. This restores normal implicit locking behavior and clears the error.

Common Scenarios and Solutions

Multiple-table UPDATEs - Ensure both source and target tables are listed in LOCK TABLES with WRITE locks.

Stored procedures - When a procedure performs LOCK TABLES, every internal statement must reference only the locked tables or unlock before accessing others.

Best Practices to Avoid This Error

Minimize use of explicit table locks. Prefer transactions with InnoDB’s row-level locking when possible.

When explicit locks are required, create helper functions to generate the full lock list automatically, or use Galaxy’s AI copilot to expand LOCK TABLES statements based on detected table names.

Related Errors and Solutions

ER_TABLE_NOT_LOCKED_FOR_WRITE (Error 1099) - Similar but triggered when attempting to write to a table locked READ ONLY. Acquire a WRITE lock.

ER_LOCK_OR_ACTIVE_TRANSACTION (Error 1192) - Signals a conflicting active transaction during a locking request. Commit or roll back the open transaction before locking.

Common Causes

Cause 1: Missing table in LOCK TABLES

The query references a table that was simply forgotten in the lock list.

Cause 2: Stored procedure accesses extra tables

A procedure called after locking touches additional tables not previously locked.

Cause 3: Temp table creation post-lock

Creating or altering temporary tables after entering locked-tables mode raises the error because those tables were not declared.

Cause 4: Privilege escalation attempts

Running DDL or administrative commands after LOCK TABLES without appropriate locks triggers the same error.

.

Related Errors

FAQs

Do I need to lock tables when using InnoDB?

No. InnoDB uses row-level locks. Prefer transactions unless you have a special use case such as advisory locking or MyISAM tables.

Does UNLOCK TABLES commit my transaction?

UNLOCK TABLES implicitly commits any active transaction. Commit first if you need transactional consistency.

Can I lock and unlock in stored procedures?

Yes, but every statement inside the procedure must honor locked-tables mode. Unlock before referencing tables outside the lock list.

How does Galaxy help avoid Error 1100?

Galaxy’s AI copilot highlights unlisted tables in a LOCK TABLES clause and auto-generates the full statement, reducing human error.

Start Querying with the Modern SQL Editor Today!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

Check out some other errors

Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie Logo
Bauhealth Logo
Truvideo Logo