MySQL MHA Master-Slave Failover: High Availability Solution
MHA Basic Concepts
MHA (Master High Availability) is a mature MySQL high availability solution.
Core Features
-
Fast Failover
- Automatically completes failover within 10-30 seconds
-
Data Consistency Guarantee
- By comparing relay log differences between slaves
-
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
- Save binary logs from crashed master
- Locate the latest slave
- Repair other slaves
- Recover unsynchronized binlog
- Master-slave switch operation
- Rebuild replication topology
Advantages Comparison
Advantages
- Fast automatic failover
- Data consistency guarantee
- Excellent performance
- Centralized monitoring management
Limitations
- Requires at least one slave
- Brief write interruption during failover
Primary-Standby Switch
Reliability-First Strategy
- Stop writes to primary
- Wait for standby to catch up with primary
- Promote standby to new primary
- Enable writes on new primary
Availability-First Strategy
- Directly promote standby to new primary
- Allow new primary to immediately accept writes
Causes of Primary-Standby Lag
- Standby machine performance issues
- Read-write pressure distribution
- Large transaction operations