How to Fix MySQL Error 1223 (ER_CANT_UPDATE_WITH_READLOCK)
You see mysql error 1223 when a query tries to change data under a read lock. To fix this failure, you must find and release the conflicting read lock first. MySQL logs this issue with code 1223, symbol ER_CANT_UPDATE_WITH_READLOCK, and SQL state HY000. The engine returns a clear message that it cannot run the query due to a conflicting read lock. Your database blocks the write step to protect data while another session reads it. What causes mysql error 1223 in your database A read lock lets
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 see mysql error 1223 when a query tries to change data under a read lock. To fix this failure, you must find and release the conflicting read lock first.
MySQL logs this issue with code 1223, symbol ER_CANT_UPDATE_WITH_READLOCK, and SQL state HY000. The engine returns a clear message that it cannot run the query due to a conflicting read lock. Your database blocks the write step to protect data while another session reads it.
What causes mysql error 1223 in your database
A read lock lets many sessions read data at the same time. Still, it stops all sessions from writing new data or changing table structures. If a session holds a read lock and tries an update, the engine stops it.
Backup tools often trigger this state when they copy tables for a safe snapshot. A script might set a global read lock to keep files consistent during the copy. While that lock stays active, any app or user trying to write will fail.
A single user session can also cause this problem on its own. An engineer might lock a table for reading and then try to update that table. Even though the same session holds the lock, a read lock forbids all writes. The database enforces this rule to stop broken states and keep storage safe.
Connection pools in an app can make this bug hard to spot. One request might set a read lock on a shared database session and fail to clear it. When the next request reuses that same session to write data, error 1223 appears.
How to find and clear the conflicting read lock
Start by checking the active process list on your MySQL server. Look for sessions that are waiting for a lock or holding open tables. You can also check the performance tables to see which thread owns the lock.
If your own session holds the table lock, tell the database to manage your tables. Once you release the read lock, your update or insert query will run fine. If you need to both read and write under a lock, request a write lock instead.
MySQL Access Governance + End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
When a backup job holds a global read lock, wait for the backup to finish. Killing a backup session mid-run can leave your team without a clean recovery file. Schedule heavy backup jobs during slow hours or run them on a read replica.
Sometimes an idle session holds a read lock because a script crashed or hung. In that case, an admin can stop that specific database thread to free the table. Do not grant extra super privileges to app roles just to bypass lock rules.
How to prevent read lock conflicts in production
Use modern storage engines that support row-level locking and safe snapshots. When your backup tool uses transaction snapshots, it does not need a long read lock. Your app can keep writing new rows while the backup reads old data.
Review your app code and database scripts for manual table lock steps. Most daily app tasks work best with standard transactions instead of manual read locks. If a script must lock a table, make sure it unlocks the table before exiting.
Set sensible timeout rules for idle sessions on your database server. When a client drops off the network, the server should close that session and drop its locks. Good session hygiene keeps one stuck script from blocking writes across your whole team.
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
What does MySQL error code 1223 mean?
Error 1223 means ER_CANT_UPDATE_WITH_READLOCK under SQL state HY000. It tells you that a session cannot run a write query because a read lock is active.
Can the session that created the read lock update the table?
No, a read lock blocks writes from every session, including the one that set it. You must release the read lock or switch to a write lock before updating data.
How do I stop backups from causing error 1223?
Run backups on a replica server or use single-transaction snapshot modes for your tables. This lets the backup read a consistent state without locking out live app writes.
Related guides
In this post