How to Fix MySQL Error 3989 (ER_SCHEMA_READ_ONLY)

Published
Length
3 min read

Luis Felipe Dias

All posts

You see mysql error 3989 when a user tries to write to a locked schema. You fix it by turning off read-only mode on that specific schema. In the engine, this failure uses the symbol ER_SCHEMA_READ_ONLY and SQLSTATE HY000. The server returns a message stating that the target schema is in read-only mode. Your server stays online, and other schemas still accept new writes as normal. Only the locked schema rejects changes to its tables or structure. Root causes of mysql error 3989 in your databas

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

You see mysql error 3989 when a user tries to write to a locked schema. You fix it by turning off read-only mode on that specific schema.

In the engine, this failure uses the symbol ER_SCHEMA_READ_ONLY and SQLSTATE HY000. The server returns a message stating that the target schema is in read-only mode. Your server stays online, and other schemas still accept new writes as normal. Only the locked schema rejects changes to its tables or structure.

Root causes of mysql error 3989 in your database

Database admins often lock a single schema during planned work or data moves. This setting stops apps and users from changing data inside that one schema. Even users with full admin rights cannot write to a locked schema. The engine blocks inserts, updates, deletes, and table changes right away.

Migration scripts are a common cause of this error in production systems. A script locks the schema before copying data to a new server. If the script fails halfway through, the schema stays in read-only mode. App servers then hit errors when they try to save new records.

Backup jobs and tenant offboarding tasks also trigger this state. A team might lock one customer schema to take a clean snapshot. Automated maintenance tools can also set this flag to prevent data drift. If no one clears the flag afterward, every write query fails.

How to diagnose the schema lock safely

Start by checking which schema caused the failure in your database error log. The error message names the exact schema that blocked the write request. Next, query the system catalog views to inspect the current schema options. Look for the read-only flag in the schema properties table.

Check if the whole server is also in read-only mode. Server-level locks and schema-level locks work separately inside the database engine. A read replica might lock the whole server, while a primary locks one schema. Knowing which lock is active helps you pick the right fix.

Read-Only Root Filesystem + MySQL Access Governance: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Before you change anything, talk to your platform or data engineering team. Ask if a data move, backup, or archive job is running right now. Check active database sessions to see if a background tool is copying tables. Unlocking a schema during a live migration can corrupt your data copy.

How to fix the error and prevent future lockouts

Once you confirm no maintenance job is running, alter the schema back to writable. You need schema alteration privileges to run this command on the server. Do not grant broad admin roles to app accounts to bypass this error. Even full admin accounts must clear the schema flag before writing data.

After you clear the read-only flag, test a small write in a staging check. Watch your app logs to confirm that normal write traffic flows again. The change takes effect right away without restarting the database server. Existing client connections do not need to log in again.

To prevent repeat incidents, put strict controls around schema change commands. Require peer approval before anyone runs an alter command on production schemas. Keep an audit log of every command that changes schema states. If a script locks a schema, make sure it logs the reason and time.

Check MySQL queries and results on the wire

MySQL grants control who logs in. They do not check single queries or mask sensitive columns once a session starts. With hoop.dev, you run an open-source proxy, a sidecar for your MySQL, inline in the MySQL wire protocol. On every query an AI agent or human runs against production MySQL, RDS, or Aurora, hoop.dev decides to pass, mask, block, or hold it for review.

Multi-statement batches and prepared queries are split and checked one by one by hoop.dev guardrails, which refuse banned queries with a native MySQL error or hold risky ones for approval. On the response path, hoop.dev data masking rewrites string values in returned rows in memory, and every decision is logged. See the MIT-licensed project on GitHub.

Frequently asked questions

What is the difference between ER_SCHEMA_READ_ONLY and global read-only mode?

Global read-only mode blocks writes across the entire database server instance. The ER_SCHEMA_READ_ONLY state only blocks writes inside one specific schema.

Can a root user write to a schema when mysql error 3989 is active?

No, the schema read-only setting blocks writes from all users, including root. An admin must alter the schema back to writable before anyone can change data.

Does fixing mysql error 3989 require a database restart?

No, turning off the read-only state on a schema is an online change. The database applies the update right away while keeping all active sessions open.

The query runs. The emails stay hidden.