1207
MySQLERRORCommonTransactionHIGH confidence
Update in a read-only transaction
Production Risk
Low — write is blocked but data is safe; fix the transaction mode.
What this means
ER_READ_ONLY_TRANSACTION (1207, SQLSTATE 25000) is raised when a DML statement (INSERT, UPDATE, DELETE) is attempted inside a transaction that was started with START TRANSACTION READ ONLY.
Why it happens
- 1Using START TRANSACTION READ ONLY and then attempting a write operation
- 2Setting the transaction access mode to READ ONLY globally or at session level
How to reproduce
trigger — this will error
trigger — this will error
SET SESSION TRANSACTION READ ONLY; START TRANSACTION; INSERT INTO orders VALUES (1, 'test'); -- ERROR 1207
expected output
ERROR 1207 (25000): Cannot execute statement in a READ ONLY transaction.
Fix
Start a read-write transaction instead
Start a read-write transaction instead
START TRANSACTION READ WRITE; INSERT INTO orders VALUES (1, 'test'); COMMIT;
Why this works
Explicitly starting a READ WRITE transaction allows DML operations.
Sources
Official documentation ↗
MySQL 8.0 — 1207 ER_READ_ONLY_TRANSACTION
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev