Symptoms
- Every insert, update and DDL statement fails with one of:
ERROR 1290 (HY000): The MySQL server is running with the --super-read-only option so it cannot execute this statementERROR 1290 (HY000): The MySQL server is running with the --read-only option so it cannot execute this statement
- Reads work. Health checks that only run
SELECT 1stay green. - It starts right after a failover, switchover, restart, maintenance event or a configuration change.
1. Find out which server the application reaches
Connect with the application's own connection string (same host name, port and user), not with your admin shortcut:
SELECT @@hostname, @@port, @@server_id, @@read_only, @@super_read_only;
SHOW REPLICA STATUS\G
Then connect to the server that should be the primary and run the same query. The answer tells you which problem you have:
| What you see | Cause | Go to |
|---|---|---|
| The application reaches a replica or the old primary | DNS, VIP, proxy or connection pool still points at the old server | Step 2 |
| The application reaches the right server, and it is read-only | Server came up read-only (config, failover tool, persisted setting) | Step 3 |
Server is a Group Replication member in SECONDARY role or ERROR state | Group Replication controls super_read_only | Step 4 |
| Aurora MySQL: you connected to a reader instance | Application uses a reader or instance endpoint for writes | Step 2 |
| Azure Database for MySQL: storage almost full | The service set the server to read-only to protect it | Step 5 |
2. Fix the routing
Writes must go to the current primary. Check what the application's host name resolves to and what it points at:
dig +short db-writer.example.internal
- DNS records or VIPs managed by Orchestrator, MHA, Keepalived or scripts: check the failover tool's log and confirm it moved the name or IP. Lower the TTL on database records so a fix applies quickly.
- MySQL Router: writes must use the read-write port (6446 for classic protocol by default), not the read-only port (6447). Check
mysqlrouter.confand the application connection string. - ProxySQL: check that the writer host group contains only the new primary:
SELECT hostgroup_id, hostname, status FROM runtime_mysql_servers; - Aurora: writes must use the cluster endpoint, not the reader endpoint or a replica's instance endpoint:
aws rds describe-db-clusters --db-cluster-identifier prod-aurora \
--query 'DBClusters[0].[Endpoint,ReaderEndpoint,DBClusterMembers[*].[DBInstanceIdentifier,IsClusterWriter]]'
Connection pools keep their existing connections after DNS changes. Once the name is right, recycle the pools by restarting or rolling the application instances.
3. Make the correct primary writable
Caution
Only make a server writable after you have confirmed it is the only primary. If the old primary is still running and writable, or a replica is still applying changes from it, two writable servers mean split brain and diverging data. Fence the old primary first (stop it, or set it read-only), and stop any replication into the new primary.
On the server that must become the primary:
-- 1. Confirm it is not replicating from another server
SHOW REPLICA STATUS\G -- expect an empty result, or stop it:
STOP REPLICA;
-- 2. Turn off read-only. Turning read_only off also turns super_read_only off.
SET GLOBAL read_only = OFF;
-- 3. Check
SELECT @@read_only, @@super_read_only;
Find out why it started read-only, so the next restart does not undo your fix:
SELECT VARIABLE_NAME, VARIABLE_SOURCE, VARIABLE_PATH, SET_TIME, SET_USER, SET_HOST
FROM performance_schema.variables_info
WHERE VARIABLE_NAME IN ('read_only', 'super_read_only');
VARIABLE_SOURCE = PERSISTED: someone ranSET PERSIST. It is stored inmysqld-auto.cnfin the data directory. RunSET PERSIST read_only = OFF;orRESET PERSIST super_read_only;on the primary.VARIABLE_SOURCE = GLOBAL,SERVERorEXPLICIT: set from an option file (VARIABLE_PATHshows which). Fix the option file.VARIABLE_SOURCE = DYNAMIC: set at runtime, for example by a failover tool.SET_USERandSET_HOSTshow who did it. Fix the tool configuration.
Many teams set super_read_only = ON in my.cnf on purpose so that no server is writable after a restart until a person or tool promotes it. In that case, do not change my.cnf. Make sure your failover runbook includes the step above.
On Amazon RDS for MySQL you cannot run SET GLOBAL read_only. read_only comes from the parameter group, and RDS sets it on read replicas. To make a replica writable, promote it with aws rds promote-read-replica --db-instance-identifier prod-mysql-replica1.
4. InnoDB Cluster and Group Replication
Do not change super_read_only by hand on a Group Replication member. The plugin sets it, and changing it on a secondary creates errant transactions.
SELECT MEMBER_HOST, MEMBER_PORT, MEMBER_STATE, MEMBER_ROLE
FROM performance_schema.replication_group_members;
- One member is
ONLINE/PRIMARY: send writes there (fix MySQL Router, step 2). - You want a different primary: in MySQL Shell, run
dba.getCluster().setPrimaryInstance('db02:3306'), or in SQL runSELECT group_replication_set_as_primary('<member_uuid>');. - Members show
ERROR,UNREACHABLEor there is no primary: the group lost quorum or the member was expelled. A member that leaves the group goes read-only by default (group_replication_exit_state_action = READ_ONLY). Follow InnoDB Cluster lost quorum.
5. Managed service storage full (Azure)
Azure Database for MySQL Flexible Server switches a server to read-only when storage is nearly full. Check the current threshold in the Azure documentation and the storage_percent metric. Add storage and enable auto-grow:
az mysql flexible-server show -g rg-prod -n mysql-prod \
--query "{size:storage.storageSizeGb, autoGrow:storage.autoGrow}"
az mysql flexible-server update -g rg-prod -n mysql-prod \
--storage-size 512 --storage-auto-grow Enabled
Storage can be increased but not reduced. Writes resume once usage is back below the threshold.
6. Verify recovery
- Run a test write with the application's user and connection string:
CREATE TABLE IF NOT EXISTS ops.write_check (id int); DROP TABLE ops.write_check;in a scratch schema, or watch application write metrics. - On every other server, confirm
@@super_read_only = 1and that replication from the new primary is running:SHOW REPLICA STATUS\GwithReplica_IO_Running: YesandReplica_SQL_Running: Yes. - Compare executed GTID sets (
SELECT @@gtid_executed;) on the old and new primary. If the old primary has transactions the new one does not, those writes were lost in the failover and need to be reconciled. See MySQL split brain.
Prevent it next time
- Health checks must test writes or check
@@read_only = 0on the writer endpoint, not just runSELECT 1. - Keep
super_read_only = ONin option files for all servers, and let the failover tool, not people, turn it off on the promoted server. - Script the failover: fence the old primary, promote, move DNS, VIP or Router, and recycle pools. Test it each quarter.
- Use short DNS TTLs and connection pool maximum lifetimes, so clients follow a failover within minutes.
- Alert when a server's
read_onlyvalue changes, usingperformance_schema.variables_infoor your monitoring agent.
Get the weekly HubDatAI email
One email a week with everything new: posts, learning sessions and videos. Free, no spam, unsubscribe in one click. What you get