Common SQL Errors

MySQL Error 1792: ER_CANT_EXECUTE_IN_READ_ONLY_TRANSACTION - How to Fix and Prevent

Galaxy Team
August 7, 2025

<p>MySQL throws error 1792 when a data-modifying statement is issued inside a READ ONLY transaction or on a read-only replica.</p>

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 1792?

<p>MySQL Error 1792: ER_CANT_EXECUTE_IN_READ_ONLY_TRANSACTION means the server blocked a write because the current transaction or replica is read only. End the read only transaction, switch to READ WRITE, or run the statement on the primary node to resolve the issue.</p>

Error Highlights

Typical Error Message

Cannot execute statement in a READ ONLY transaction.

Error Type

Transaction Error

Language

MySQL

Symbol

ER_CANT_EXECUTE_IN_READ_ONLY_TRANSACTION

Error Code

1792

SQL State

25006

Explanation

Table of Contents

What is MySQL error 1792: ER_CANT_EXECUTE_IN_READ_ONLY_TRANSACTION?

MySQL returns this error when a statement that modifies data or schema is executed while the current transaction is marked READ ONLY or the session is connected to a read only replica. The server protects data integrity by forbidding any write during such transactions.

What causes this error?

The storage engine checks transaction characteristics at execution time. If START TRANSACTION READ ONLY or SET SESSION TRANSACTION READ ONLY was issued, any INSERT, UPDATE, DELETE, REPLACE, CREATE, ALTER or DROP fails with error 1792. The same happens on replicas running with super_read_only or read_only flags.

How to fix MySQL error 1792

Convert the transaction to READ WRITE, end the current read only transaction, or route the query to a writable primary. On replicas, temporarily disable super_read_only or read_only if safe and permitted.

Common scenarios and solutions

Application pools often default to read only for reporting but later reuse the same connection for writes. Explicitly issue SET SESSION TRANSACTION READ WRITE before the first insert, or open a fresh primary connection. In stored procedures, check @@tx_read_only and raise custom messages to avoid silent failure.

Best practices to avoid this error

Separate read and write workloads using dedicated connection pools. Close transactions quickly to reduce state leakage. Use Galaxy connection labels to mark queries as read or write, ensuring that modifying statements are never routed to a replica.

Common Causes

Read only transaction declared

START TRANSACTION READ ONLY or SET SESSION TRANSACTION READ ONLY sets the transaction to read only, causing subsequent writes to fail.

Connected to a replica

A client connected to a replica with read_only=ON or super_read_only=ON triggers the error for any write.

Connection pool reuse

Applications may reuse a read only connection for a write without resetting the session, leading to unexpected failures.

Related Errors

MySQL error 1290: server is running with the --read-only option

Occurs when attempting writes on a server started in full read only mode.

MySQL error 1205: lock wait timeout exceeded

Long running transactions on replicas can also trigger lock wait issues.

MySQL error 1227: access denied for super_read_only change

Appears when disabling super_read_only without the required SUPER privilege.

FAQs

Can I turn a READ ONLY transaction into READ WRITE without closing it?

No. You must commit or roll back the transaction and start a new one with READ WRITE.

Does SELECT trigger error 1792?

No. Pure SELECT statements are allowed in read only transactions.

Why do I get the error on an Aurora read replica?

Aurora replicas are inherently read only. Route all writes to the writer endpoint.

How does Galaxy help prevent this error?

Galaxy tags connections as read or write and blocks modifying queries from being executed on read only replicas, preventing error 1792.

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