MySQL 1179: Transaction is read-only.

When encountering the error 1179: Transaction is read-only in MySQL, follow these steps:

  1. Check the Transaction Read-Only Setting: Determine if the transaction is explicitly set to read-only. Run the following query within your session:



SHOW VARIABLES LIKE 'transactionreadonly';

If the value is `ON`, your transaction is set to read-only. To change it for the current session, execute:

SET SESSION transactionreadonly = OFF;

  1. Inspect the Transaction Isolation Level: The transaction isolation level might be affecting the behavior. Check the current level by running:



SELECT @@GLOBAL.txisolation, @@txisolation;

If necessary, adjust the isolation level for your session. For example, to set it to READ-COMMITTED, use:

SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;

  1. Review User Permissions: Ensure your MySQL user has the necessary permissions to perform write operations. Verify permissions with:



SHOW GRANTS FOR CURRENT_USER;

If write permissions are missing, you might need to contact someone with administrative privileges or, if you have the necessary credentials, grant the permissions yourself (ensure you understand the security implications):

GRANT INSERT, UPDATE, DELETE ON yourdatabasename.* TO 'yourusername'@'yourhost';

Replace `yourdatabasename`, `yourusername`, and `yourhost` with the actual database name, your MySQL username, and host, respectively.

  1. Check if Using a Read-Only Replica: If you're connected to a read-only replica of the database, you cannot perform write operations. Verify the server's role and switch to the primary (or master) server if necessary.



  1. Inspect System Variables: Some system variables can affect the read-only status of transactions. Check the global read_only variable by executing:



SHOW GLOBAL VARIABLES LIKE 'read_only';

If it’s set to `ON` and you have the necessary privileges, you can turn it off with:

SET GLOBAL read_only = OFF;

Be cautious with this step as it affects the entire database server.

  1. Analyze Disk Space: Ensure the server has sufficient disk space. Running out of space can result in read-only mode to prevent data corruption. Check the disk space outside of MySQL using your operating system’s tools (like `df -h` on Linux).



  1. Review Database Logs: Look for any errors or warnings in the MySQL error log that might indicate why the transaction was set to read-only. The location of the log file varies, but you can find it by running:



SHOW VARIABLES LIKE 'log_error';

Then, check the contents of the log file for relevant messages.

Proceed with caution and ensure you understand the implications of each action, especially when modifying global variables or granting permissions.

Never debug

MySQL

manually again

Let Dr. Droid create custom investigation plans for your infrastructure.

Start Free POC (15-min setup) →
Automate Debugging for
MySQL
See how Dr. Droid creates investigation plans for your infrastructure.

MORE ISSUES

Made with ❤️ in Bangalore & San Francisco 🏢

Doctor Droid