Common SQL Errors

MySQL Error 1099: ER_TABLE_NOT_LOCKED_FOR_WRITE - How to Fix and Prevent

Galaxy Team
August 5, 2025

The server raises ER_TABLE_NOT_LOCKED_FOR_WRITE when a write statement targets a table that was only READ locked in the current session.

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 code 1099?

MySQL Error 1099: ER_TABLE_NOT_LOCKED_FOR_WRITE means the table is locked for READ only, so INSERT, UPDATE, or DELETE cannot run. Issue UNLOCK TABLES or lock the table with WRITE before executing the statement to resolve the problem.

Error Highlights

Typical Error Message

Table '%s' was locked with a READ lock and can't be

Error Type

Locking Error

Language

MySQL

Symbol

ER_TABLE_NOT_LOCKED_FOR_WRITE

Error Code

1099

SQL State

Explanation

Table of Contents

What is MySQL Error 1099 (ER_TABLE_NOT_LOCKED_FOR_WRITE)?

Error 1099 appears with the message: "Table '%s' was locked with a READ lock and can't be updated." The server blocks any INSERT, UPDATE, DELETE, or REPLACE that targets a table currently locked for READ by the same session.

The error is connection specific. One thread can hold a READ lock, attempt a write, and receive 1099 even while other connections hold no lock at all.

It surfaces under LOCK TABLES statements, explicit or generated by some backup utilities.

What Causes This Error?

A session issues LOCK TABLES ... READ and then tries to modify the same table without upgrading to WRITE. MySQL enforces consistency by refusing the change.

Using mysqldump --lock-tables keeps tables READ locked during the dump.

Accidentally running update scripts in the same connection triggers the error.

Stored procedures or triggers that call a write statement while the caller holds only READ locks also produce 1099.

How to Fix MySQL Error 1099

Release the READ lock before modifying data.

Execute UNLOCK TABLES or end the transaction to remove all locks.

If you still need a lock, re-lock the table with WRITE or WRITE LOCAL, then run the modification.

When using mysqldump, add the --single-transaction flag instead of --lock-tables so backups run without long READ locks.

Common Scenarios and Solutions

Dump plus patch - A developer dumps a table with LOCK TABLES, edits data, and gets 1099.

Solution: run UNLOCK TABLES before the patch.

Long-running report - Analytics code locks a table READ, loops for analysis, then tries an UPDATE. Fix: split read and write phases into separate connections.

Trigger recursion - A trigger fires and writes back to the same table locked READ. Solution: acquire WRITE lock or redesign trigger logic.

Best Practices to Avoid This Error

Always match lock intent with operation type.

Use WRITE locks for sessions that may modify data.

Favor transaction isolation (START TRANSACTION) with SELECT ... FOR UPDATE instead of explicit LOCK TABLES when possible.

In Galaxy's SQL editor, run read-only exports in one tab and perform data fixes in another to ensure separate lock scopes.

Related Errors and Solutions

Error 1100 (ER_TABLE_NOT_LOCKED) - Happens when a table needs any lock but isn’t locked at all.

Lock the table appropriately.

Error 1205 (Lock wait timeout) - A thread waits too long for a lock. Reduce contention or increase innodb_lock_wait_timeout.

Error 1213 (Deadlock found) - Circular lock dependency detected. Re-order statements or use smaller transactions.

.

Common Causes

READ lock held by same session

The connection explicitly executed LOCK TABLES table_name READ and then tried to perform a write.

mysqldump with --lock-tables

Backup utilities lock tables in READ mode during export; if a post-dump script runs in the same session, writes fail.

Triggers or procedures

Server-side code that writes to a table while the caller holds only a READ lock causes the error.

Mixed-purpose transactions

Applications combining analytical SELECTs with subsequent updates under the same READ lock encounter 1099.

.

Related Errors

FAQs

Why does Error 1099 only happen in my script but not in the client?

Your script likely issues LOCK TABLES READ before writing. The interactive client uses implicit locks, so the problem is hidden there.

Can I ignore Error 1099 safely?

No. Ignoring it means your write never executed. Always fix the lock state instead.

Is UNLOCK TABLES the same as COMMIT?

UNLOCK TABLES releases explicit table locks, while COMMIT ends a transaction. They are separate commands and may both be required.

How does Galaxy help prevent this error?

Galaxy lets you run read-only queries in isolated tabs, reducing chances of mixing READ locks with write operations in the same session.

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