MySQL MHA Master-Slave Failover: High Availability Solution

MHA Basic Concepts

MHA (Master High Availability) is a mature MySQL high availability solution.

Core Features

  1. Fast Failover

    • Automatically completes failover within 10-30 seconds
  2. Data Consistency Guarantee

    • By comparing relay log differences between slaves
  3. Flexible Deployment

    • Supports standard master-slave replication architecture

Components

1. MHA Manager (Management Node)

  • Continuously monitors Master node health status
  • Automatically triggers failover process

2. MHA Node (Data Node)

  • Real-time saves and transfers binary logs
  • Receives and applies relay logs

Fault Handling Process

  1. Save binary logs from crashed master
  2. Locate the latest slave
  3. Repair other slaves
  4. Recover unsynchronized binlog
  5. Master-slave switch operation
  6. Rebuild replication topology

Advantages Comparison

Advantages

  1. Fast automatic failover
  2. Data consistency guarantee
  3. Excellent performance
  4. Centralized monitoring management

Limitations

  1. Requires at least one slave
  2. Brief write interruption during failover

Primary-Standby Switch

Reliability-First Strategy

  1. Stop writes to primary
  2. Wait for standby to catch up with primary
  3. Promote standby to new primary
  4. Enable writes on new primary

Availability-First Strategy

  1. Directly promote standby to new primary
  2. Allow new primary to immediately accept writes

Causes of Primary-Standby Lag

  1. Standby machine performance issues
  2. Read-write pressure distribution
  3. Large transaction operations