How to Fix: The MySQL Server is Running with the --read-only Option So It Cannot Execute This Statement
Robert Cooper
Robert Cooper Senior Engineer at Basedash
· January 31, 2025
Robert Cooper
Robert Cooper Senior Engineer at Basedash
· January 31, 2025
When you encounter the message “The MySQL server is running with the —read-only option so it cannot execute this statement,” it typically means the server has been set to a read-only state, preventing write operations. This guide is designed for engineers looking to resolve this issue in a MySQL environment.
The --read-only option in MySQL restricts write operations (like INSERT, UPDATE, DELETE) for all users except those with the SUPER privilege. This setting is often used in replication setups or for maintenance tasks.
To confirm if your MySQL server is running in read-only mode, execute the following SQL command:
SHOW VARIABLES LIKE 'read_only';
If the value is ON, then the server is in read-only mode.
To disable read-only mode, you need the SUPER privilege. Execute the following command:
SET GLOBAL read_only = OFF;
Alternatively, if you have access to the server’s configuration file (my.cnf or my.ini), locate the line read-only = 1 and change it to read-only = 0 or remove the line. Then, restart the MySQL server.
If the server is not in read-only mode, but you still get the error, check your user privileges. Run:
SHOW GRANTS FOR 'your_username'@'your_host';
Ensure you have the necessary privileges to perform the operation you’re attempting.
In replication setups, the slave is often set to read-only. If you’re working on a slave server, consider if you should be writing to this server or redirecting the write operations to the master server.
If your MySQL server is managed by a cloud service provider, the read-only settings might be controlled through their management console. Check the database configuration in your cloud provider’s dashboard.
To avoid this issue in the future, consider setting up monitoring and alerting for the read-only status of your MySQL servers. This can be done through custom scripts or monitoring tools.
During troubleshooting, Basedash helps teams move faster by combining AI-assisted analysis with direct SQL access, so you can validate fixes, monitor results, and share clear dashboards after incidents are resolved.
By following these steps, you should be able to identify and resolve the issue of MySQL running in read-only mode. Remember to check the MySQL server settings, user privileges, and consider the replication setup and cloud service configurations in your troubleshooting process.
Written by
Senior Engineer at Basedash
Robert Cooper is a senior engineer at Basedash who builds full-stack product systems across SQL data infrastructure, APIs, and frontend architecture. His work focuses on application performance, developer velocity, and reliable self-hosted workflows that make data operations easier for teams at scale.
Basedash lets you build charts, dashboards, and reports in seconds using all your data.