How to Fix MySQL Error 1100 (ER_TABLE_NOT_LOCKED)

Published
Length
3 min read

Luis Felipe Dias

All posts

You trigger mysql error 1100 when a session reads a table outside its active lock list. To fix it, add every target table and alias to your lock request or release locks first. Database sessions use explicit table locks to stop other users from changing data mid-job. Once a session requests a table lock, the database engine enters a strict mode. In this mode, the session can only touch tables named in that lock command. If your query touches one extra table, the database blocks the query right

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

You trigger mysql error 1100 when a session reads a table outside its active lock list. To fix it, add every target table and alias to your lock request or release locks first.

Database sessions use explicit table locks to stop other users from changing data mid-job. Once a session requests a table lock, the database engine enters a strict mode. In this mode, the session can only touch tables named in that lock command. If your query touches one extra table, the database blocks the query right away. This rule keeps data safe during multi-step tasks, backups, and batch updates.

Root causes of mysql error 1100 in the database engine

The database server tracks this issue under the ER_TABLE_NOT_LOCKED symbol and HY000 state. The server message states that your target table was not locked with LOCK TABLES. This happens because a lock request builds a strict boundary around your session. You cannot read or write outside that boundary until you drop the active locks.

Table aliases are a very common trap for developers and database admins. If a query uses an alias, you must lock that exact alias too. Locking the base table name alone will not cover the alias in your query. The database treats the base name and the alias as two separate targets.

Hidden queries also trigger this failure in busy production apps. Views and triggers often touch extra tables behind the scenes. When you lock a main table, the database checks every table inside linked triggers too. If your lock list misses one table in a trigger, the whole query fails.

Shared connection pools can also spread this problem across an app. One job might lock a table and fail before it cleans up the session. The pool then hands that locked session to a new app task. The next query fails because the old lock boundary is still active.

How to find and fix the failure in production

Start by finding the exact query that failed in your database logs. Read the server message to see which table or alias caused the block. Check if that name is a real table, a view, or a query alias. Next, inspect the full session history that ran right before the failure.

MySQL Access Governance + End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Look for the lock command that started the restricted session mode. Compare every table and alias in your failed query against that initial lock list. Do not forget to check any views or triggers tied to your target tables. Every single table in the chain must appear in the lock step.

You have two safe ways to fix this error in a live system. First, you can update the lock request to include all missing tables and aliases. Make sure you ask for read or write locks that match your query needs. Second, you can release the active table locks before you run the next query.

For modern storage engines, you might not need explicit table locks at all. Standard database transactions handle row consistency well without freezing whole tables. Replacing manual table locks with standard transactions often stops this error for good. It also helps your app handle more users at the same time.

Preventing lock issues in shared database sessions

Teams should set clear rules for how apps and admins run manual locks. Never give broad superuser roles just to work around a blocked session. High privileges will not bypass the ER_TABLE_NOT_LOCKED rule anyway. Even a root user must follow the strict lock boundary once it starts.

When you run ad-hoc maintenance scripts, keep your lock windows very short. Always pair your lock step with a cleanup step at the end of the script. If you use connection pools, make sure the pool resets session state between jobs. Check your query logs often to catch broken lock patterns early. If your tables hold sensitive data like emails or card numbers, use data masking. Masking rewrites matched fields in results while you test queries in live sessions.

Check MySQL queries and results on the wire

MySQL grants control who logs in. They do not check single queries or mask sensitive columns once a session starts. With hoop.dev, you run an open-source proxy, a sidecar for your MySQL, inline in the MySQL wire protocol. On every query an AI agent or human runs against production MySQL, RDS, or Aurora, hoop.dev decides to pass, mask, block, or hold it for review.

Multi-statement batches and prepared queries are split and checked one by one by hoop.dev guardrails, which refuse banned queries with a native MySQL error or hold risky ones for approval. On the response path, hoop.dev data masking rewrites string values in returned rows in memory, and every decision is logged. See the MIT-licensed project on GitHub.

Frequently asked questions

Why does mysql error 1100 happen when the table is already locked?

You likely used a table alias in your query without locking that exact alias. If you alias a table, you must lock both the table and the alias name.

Do triggers and views cause the ER_TABLE_NOT_LOCKED error?

Yes, the database checks every base table inside a view or trigger during a lock. You must lock the main table and every table referenced by the view or trigger.

Can higher user permissions bypass this table lock restriction?

No, this error is a session state rule, not a user permission check. Even full admin accounts must lock all target tables or release active locks first.

The query runs. The emails stay hidden.