Databases 4 min read

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.

Java High-Performance Architecture
Java High-Performance Architecture
Java High-Performance Architecture
How Dual-Master MySQL Replication Eliminates Downtime and Simplifies Failover

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.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

mysqlDatabase MaintenanceDual-Master
Java High-Performance Architecture
Written by

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.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.