How to Fix MySQL Error 1207 (ER_READ_ONLY_TRANSACTION)

Published
Length
3 min read

Luis Felipe Dias

All posts

You get mysql error 1207 when a query tries to take an update lock inside a read uncommitted transaction. You can fix it by raising the isolation level or removing the locking read from your query. MySQL logs this event under the symbol ER_READ_ONLY_TRANSACTION and SQLSTATE 25000. The official message states that update locks cannot be acquired during a READ UNCOMMITTED transaction. This rule stops sessions from mixing dirty reads with row locks that prepare data for writes. What causes mysql

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 get mysql error 1207 when a query tries to take an update lock inside a read uncommitted transaction. You can fix it by raising the isolation level or removing the locking read from your query.

MySQL logs this event under the symbol ER_READ_ONLY_TRANSACTION and SQLSTATE 25000. The official message states that update locks cannot be acquired during a READ UNCOMMITTED transaction. This rule stops sessions from mixing dirty reads with row locks that prepare data for writes.

What causes mysql error 1207 in your database

This failure happens when your session settings clash with your query locking needs. A session set to the read uncommitted level can read rows that other transactions have not committed yet. Because that data might roll back at any second, the engine blocks the session from taking update locks.

App code often triggers this bug through object-relational mappers or shared connection pools. One part of the app lowers the isolation level to run a fast report. The pool then hands that same session to a payment job without resetting the state. When the payment job tries to lock a row before an update, the engine rejects the query.

Replica nodes and read-only transactions can also surface this error code. If an engineer starts a read-only transaction block and runs a locking read, the database stops the command. The engine enforces SQLSTATE 25000 to protect transaction rules across the cluster.

How to diagnose and fix the failure in production

Start by checking the active isolation level on the failing database session. Compare the session state with the global database rule to see where the change happens. Check your app logs to find the exact query that asked for an update lock.

Next, inspect how your connection pool handles session cleanup between requests. Make sure the pool resets session states before handing a connection to a new worker. If a reporting task needs read uncommitted mode, scope that rule to that single transaction only. Once the report finishes, the session will return to normal behavior.

Read-Only Root Filesystem + MySQL Access Governance: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

To fix the broken query, align the transaction mode with the work it performs. If the job must lock rows and change data, run it under repeatable read or read committed mode. If the job only reads data and does not need locks, drop the lock request from the query. Never grant broad root roles or turn off safety checks just to bypass a transaction error.

How to prevent transaction lock conflicts in app workflows

Good database hygiene stops isolation bugs before they reach live users. Split your read-heavy analytics queries from your core write workloads. Send reporting traffic to dedicated read replicas so those sessions never mix with write pools.

You should also review ad-hoc queries that engineers run during live incidents. An engineer might copy a locking query into a session that has strict read rules. Clear guardrails and query checks help teams spot these mismatches early. When every session uses a clean state, update locks work as expected.

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 SQLSTATE 25000 mean in MySQL?

SQLSTATE 25000 means an invalid transaction state stopped your command. In MySQL, it pairs with error 1207 when a session tries to lock rows during a read-only or read uncommitted block.

Why can connection pools trigger ER_READ_ONLY_TRANSACTION?

Connection pools reuse open sessions across many app requests. If one task sets the session to read uncommitted and does not reset it, the next task inherits that rule and fails on update locks.

Can I fix error 1207 by granting more user permissions?

No, user permissions do not cause or fix this error. Error 1207 comes from transaction isolation rules. As a result, you must change the transaction mode or remove the lock request from the query.

The query runs. The emails stay hidden.