Skip to content
DevOps AI ToolKit
Newsletter
All prompts
AI for MySQL Difficulty: Advanced ClaudeChatGPTCursor

MySQL Replica Promotion & Failover Runbook Prompt

Produce a step-by-step, safety-checked runbook to promote a replica to primary during planned or emergency failover without split-brain or data loss.

Target user
On-call DBAs and SREs performing MySQL failover under pressure
Difficulty
Advanced
Tools
Claude, ChatGPT, Cursor

The prompt

You are a senior MySQL/MariaDB DBA writing failover runbooks that a stressed on-call engineer can follow at 3am. You understand GTID-based replication, relay-log draining, errant transactions, read_only/super_read_only fencing, replica repointing (CHANGE REPLICATION SOURCE), and the split-brain failure modes that make emergency failover dangerous.

I will provide:
- Topology: primary + replica list, replication type (async / semisync), GTID or file-position based: [DESCRIBE]
- The scenario: planned switchover vs emergency (primary crashed / unreachable): [STATE]
- Whether a failover orchestrator (Orchestrator, MHA, Group Replication, MySQL Router/InnoDB Cluster) is in place or this is manual: [DESCRIBE]
- Application connection method (VIP, DNS, proxy such as ProxySQL, hardcoded host): [DESCRIBE]
- Durability/RPO requirement (how much committed data may be lost): [STATE]

Produce a runbook with:

1. **Pre-flight checks** — confirm which replica is most up to date (GTID_EXECUTED comparison / Seconds_Behind_Source), check for errant transactions (GTIDs on a replica not present on others), verify semisync ACK state, and confirm the candidate's data is consistent.
2. **Fence the old primary** — for emergency, isolate it (set super_read_only, kill sessions, or network-fence) so it cannot accept writes if it comes back; for planned, set the primary read_only and let replicas drain to equal GTID sets.
3. **Drain and promote** — wait for the candidate to apply all relay-log events, then RESET REPLICA / stop replication and clear read_only; capture the new primary's coordinates.
4. **Repoint the other replicas** at the new primary via CHANGE REPLICATION SOURCE (with AUTO_POSITION for GTID) and verify they connect and catch up.
5. **Redirect application traffic** — move the VIP/DNS/proxy target; describe the exact cutover and how to verify writes land on the new primary.
6. **Post-failover validation** — confirm replication health, no errant transactions, monitoring re-armed, and document how to rebuild/re-slave the old primary safely.

Include, at each destructive step, the exact command, the expected output, and the STOP/rollback condition.

Output: an ordered runbook with copy-pasteable commands, per-step verification, an explicit split-brain-prevention step, the RPO impact if the candidate was behind, and a rebuild plan for the old primary.

Guardrails: never promote without confirming relay-log drain and checking errant transactions; always fence the old primary before redirecting writes; state the exact data-loss (RPO) if promoting a lagging replica in an emergency; treat the runbook as reviewed procedure, not to be improvised, and require a second operator to confirm destructive steps where possible.

Run this prompt with AI

Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.

Why this prompt works

Failover is the highest-stakes routine operation a DBA performs, and it usually happens under time pressure with adrenaline running. This prompt makes the model produce an ordered runbook with copy-pasteable commands, expected output, and explicit STOP conditions at every destructive step — the format an exhausted on-call engineer can actually follow without improvising. Improvisation during failover is exactly how split-brain happens.

The prompt front-loads the two decisions that determine whether failover is safe: which replica is genuinely most up to date, and whether the old primary can be prevented from accepting writes. By demanding a GTID_EXECUTED comparison, an errant-transaction check, and an explicit fencing step before any traffic moves, it targets the two failure modes — promoting a lagging replica and creating two writable primaries — that cause irreversible data loss.

It also insists on stating the real RPO when an emergency forces promotion of a replica that was behind. That honesty matters: sometimes the right call is to lose a few seconds of writes to restore service, but that must be a conscious, documented decision rather than a surprise discovered later. The rebuild plan for the old primary closes the loop so the topology returns to a safe steady state instead of a fragile one-node island.

Related prompts

More MySQL prompts & error guides

Browse every MySQL prompt and troubleshooting guide in one place.

Free download · 368-page PDF

Reading prompts? Get all 500 in one free PDF

500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.

  • 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
  • Instant PDF download — yours free, forever
  • Plus one practical AI-workflow email a week (no spam)

Single opt-in · unsubscribe anytime · no spam.