How to Fix MySQL Error 4094 (ER_OPERATION_NOT_ALLOWED_WHILE_PRIMARY_CHANGE_IS_RUNNING)
You get mysql error 4094 when the database runs a primary node switch. You fix it by waiting for the switch to finish or checking stuck sessions. This error links to the official symbol ER_OPERATION_NOT_ALLOWED_WHILE_PRIMARY_CHANGE_IS_RUNNING and SQLSTATE HY000. The engine blocks all new queries while the primary change function runs. This block keeps data safe across the group replication cluster during a role swap. What causes mysql error 4094 in group replication In a single-primary clust
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 get mysql error 4094 when the database runs a primary node switch. You fix it by waiting for the switch to finish or checking stuck sessions.
This error links to the official symbol ER_OPERATION_NOT_ALLOWED_WHILE_PRIMARY_CHANGE_IS_RUNNING and SQLSTATE HY000. The engine blocks all new queries while the primary change function runs. This block keeps data safe across the group replication cluster during a role swap.
What causes mysql error 4094 in group replication
In a single-primary cluster, only one server accepts write requests at a time. Sometimes an admin or an automated tool picks a new primary server. The cluster then runs an internal function to move the primary role over.
During this move, the cluster must keep all nodes in sync. The old primary waits for running transactions to finish before it steps down. The new primary applies its backlog of changes before it takes over.
While this handoff happens, the database rejects or holds new queries. If an app sends a query right then, the server returns mysql error 4094. The error message notes that all queries stay blocked while the change runs. It also tells you to check the timeout setting for the switch.
A fast switch takes only a second or two on a healthy cluster. If the error lasts a long time, a transaction is holding up the switch. Long read queries, open transactions, or slow network links often delay the handoff.
How to check the cluster and fix the block
Start by checking the status of your group replication nodes. Log in with a read-only admin role to inspect the active process list. Look for old transactions that started before the primary switch began.
If an idle client holds an open transaction, it blocks the role change. Ask the app team to close the idle session or stop the stuck query. Once the old transaction ends, the primary change can finish its work.
MySQL Access Governance + End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
You should also check the replication queue on the new primary server. High replication lag forces the switch function to wait until the queue clears. Wait for the node to catch up rather than forcing a hard restart.
Check the timeout parameter mentioned in the official error message as well. This timeout sets how long the cluster waits for running transactions to finish. If you set a fair timeout, the function cancels slow queries when time runs out.
How to prevent query blocks during future switches
Plan primary changes during low traffic hours whenever you can. Lower traffic means fewer open transactions that can hold up the role swap. Your switch will finish much faster when the server load is light.
Set up your app pools to retry failed queries after a short pause. When a switch happens, a brief retry lets the app recover on its own. Your users will not see errors if the app waits a second and retries.
Keep database transactions short and fast across all your services. Do not allow developers to run manual queries that keeps the session active for minutes. Short transactions let the cluster switch primary nodes with very little delay.
Limit who can run cluster control functions in your production database. Only senior admins and trusted automation tools should trigger a primary change. Also check that data masking rewrites matched fields like emails or card numbers in results.
Inspect every MySQL query and response in flight
Static grants and network rules block bad logins. They cannot pause a risky query for review or mask emails in a result set. By design, hoop.dev sits inline in the MySQL protocol as a sidecar for your MySQL. For every plain query, prepared statement, or cursor an agent or human runs in production, hoop.dev decides to pass, mask, block, or hold it for review.
First, hoop.dev guardrails block banned actions before MySQL runs them, and an AI Analyzer you configure can score intent or escalate for approval. Next, hoop.dev data masking rewrites sensitive string columns in results in memory, and every verdict goes to the audit trail. Find the open-source binary on GitHub.
Frequently asked questions
What does SQLSTATE HY000 mean for error 4094?
SQLSTATE HY000 is a general error code used by the MySQL engine. You must read the specific 4094 code to see that a primary switch is running.
Will killing the primary switch function break the cluster?
Stopping the switch mid-way is safe because the cluster will roll back the change. Still, it is better to end the stuck client query that blocks the switch.
Why does a read query trigger mysql error 4094?
The engine blocks all queries during the final phase of a primary change. This rule stops dirty reads and keeps data consistent while server roles change.
Related guides
In this post