How to Fix MySQL Error 4047 (ER_WARN_SQL_AFTER_MTS_GAPS_GAP_NOT_CALCULATED)
You see mysql error 4047 when you start replication with a gap recovery rule while automatic transaction positioning is active. You fix this issue by letting the replica recover missing transactions on its own or by running normal start commands without the gap clause. Database teams often see this warning during recovery work on multi-threaded replicas. Multi-threaded workers process changes in parallel to keep replicas fast. When a replica stops unexpectedly, some worker threads finish later
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 4047 when you start replication with a gap recovery rule while automatic transaction positioning is active. You fix this issue by letting the replica recover missing transactions on its own or by running normal start commands without the gap clause.
Database teams often see this warning during recovery work on multi-threaded replicas. Multi-threaded workers process changes in parallel to keep replicas fast. When a replica stops unexpectedly, some worker threads finish later changes before earlier changes finish. This creates gaps in the transaction log. Older setups needed a special stop rule to fill those gaps before doing maintenance. Modern setups with global transaction IDs handle those gaps on their own.
What causes mysql error 4047 in replication
The database engine logs mysql error 4047 under symbol ER_WARN_SQL_AFTER_MTS_GAPS_GAP_NOT_CALCULATED and SQLSTATE HY000. The engine triggers this message when an operator starts a channel with a gap stop condition while global transaction IDs and auto positioning are active.
In older file-position replication, the database had to calculate exact relay log gaps after a crash. Operators told the SQL thread to run until all multi-threaded gaps were closed. Then they could safely change settings or switch sources. Still, when global transaction IDs and auto positioning are on, the replica tracks every completed transaction in a set. The engine does not need to calculate relay log gaps because it compares transaction sets directly with the source. Using the old stop condition tells the engine to do math it skips in this mode.
How to diagnose the warning safely
First, check your replica status and server error logs to see which replication channel triggered the warning. Your team does not need full superuser roles just to inspect replication health. Grant read-only monitoring permissions so engineers can check channel status safely.
Look at two main settings on the replica: global transaction ID mode and channel auto positioning. If both features are active, your scripts or operators are sending an outdated start command. Check your automated recovery scripts or maintenance procedures. Many teams keep old recovery commands from before they turned on global transaction IDs. When those old commands run on a modern cluster, the engine raises warning 4047 and skips gap calculation.
MySQL Access Governance + End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
How to fix the replication start flow
Fixing this warning is simple and safe for production data. Update your operational scripts so they start replication without the multi-threaded gap stop condition. When auto positioning is on, the replica fetches any missing transactions from the source by default.
If your team needs to stop the replica at a specific point for maintenance, use transaction ID stop rules instead. Transaction ID stop rules work well with auto positioning and parallel workers. Test the updated recovery command on a staging replica first. Once you verify that the warning disappears from the logs, update your production maintenance procedures. Always keep strict role permissions in place when running replication changes on live databases. If your queries also return personal data during checks, make sure masking rewrites matched fields like emails or phone 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
Does mysql error 4047 stop replication from running?
No, this message acts as a warning with SQLSTATE HY000. The engine informs you that it did not calculate gaps because auto positioning handles transaction tracking instead.
Why do multi-threaded replicas create transaction gaps?
Parallel worker threads apply different transactions at the same time. If one fast worker finishes a later transaction before a slow worker finishes an earlier one, a temporary gap appears.
Should we turn off auto positioning to fix error 4047?
No, you should keep auto positioning turned on. It makes crash recovery safer and easier. Instead, remove the outdated gap stop clause from your start command.
Short role checks help teams work fast. Simple rules make each review clear. Good logs keep every team safe. Scoped keys stop bad changes early.
Related guides
In this post