// MySQL error reference

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
Error message
Cannot execute statement in a READ ONLY transaction.

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 = ON left on a pooled connection.

How to fix it

  1. Check the session setting.

    SELECT @@transaction_read_only;
  2. 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

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.

// fewer errors, faster fixes

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.