How Dual-Master MySQL Replication Eliminates Downtime and Simplifies Failover
Dual‑master MySQL replication lets two servers act as each other's master and slave, preventing circular replication through unique server‑ids, reducing maintenance overhead, enabling automatic failover, and allowing only one node to handle writes to avoid data conflicts, thereby minimizing downtime.
The commonly used replication method is a primary‑secondary (master‑slave) architecture, but sometimes specific scenarios require switching the master.
When performing maintenance on the master, you may need to stop MySQL service. To minimize downtime, the best practice is to promote a slave to become the master to handle writes.
However, the original master’s data then becomes inconsistent with the actual data. When the original master restarts and can serve, data inconsistency forces you to reverse the master‑slave relationship, rebuild the replication environment, and configure the original master as a slave for read‑only service. Rebuilding replication adds considerable work, and without proper backups the process can be very cumbersome.
To solve this, you can set up a Dual‑Master environment where two MySQL servers treat each other as their master and themselves as the other's slave. Thus any change on one side is replicated to the other.
Will this cause circular replication between the two MySQL instances? MySQL anticipates this; the binary log records a server‑id, which must be distinct for each server in replication. With unique server‑ids, MySQL can identify the origin of a change and avoid loops.
With Dual‑Master replication, you avoid the need to rebuild the replication environment after normal maintenance, because each side records its current replication position and automatically resumes from that point without manual intervention, greatly reducing maintenance cost.
Moreover, combined with third‑party HA management tools, a Dual‑Master setup can automatically switch service to the other node if the current master fails, cutting downtime without manual action.
Note that a Dual‑Master environment is not intended for both nodes to accept writes. In normal operation, only one side is enabled for writes while the other provides read‑only service or remains idle as a standby.
Why enable writes on only one side? To prevent data conflicts and ensure consistency.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Java High-Performance Architecture
Sharing Java development articles and resources, including SSM architecture and the Spring ecosystem (Spring Boot, Spring Cloud, MyBatis, Dubbo, Docker), Zookeeper, Redis, architecture design, microservices, message queues, Git, etc.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
