MySQL error 1792: Write in a READ ONLY transaction
A write was attempted inside a transaction started as READ ONLY, or on a session whose default is read-only.
- Error number
1792- Name
ER_CANT_EXECUTE_IN_READ_ONLY_TRANSACTION- SQLSTATE
25006- Category
- Transactions and locking
What it means
A transaction started with START TRANSACTION READ ONLY, or a session with transaction_read_only on, may not change tables (temporary tables excepted). Any INSERT, UPDATE, DELETE or DDL fails with 1792. Drivers and frameworks often mark transactions read-only for queries they think are reads.
Common causes
- A framework read-only transaction (for example a read-only annotation or replica routing) that ends up running a write.
SET SESSION transaction_read_only = ONleft on a pooled connection.
How to fix it
-
Check the session setting.
SELECT @@transaction_read_only;
-
Start a read-write transaction for the write, or fix the code path that marked it read-only.
START TRANSACTION READ WRITE;
Related errors
More transactions and locking errors
1205Lock wait timeout exceeded1213Deadlock found when trying to get lock3572Lock couldn't be acquired with NOWAIT1206Locks exceed the lock table size3024Maximum statement execution time exceeded
The code and message text are from the MySQL 8.4 Error Message Reference. Browse the full MySQL error list or search every database error.
Work on MySQL in SQLly
A native SQL client for macOS, Windows and Linux with schema-aware IntelliSense, guardrails for risky statements and clear error messages, for MySQL and the other databases you use.