What is Replication in MySQL?
Replication in MySQL is a process of copying data from one database server (master) to one or more servers (slaves/replicas). It ensures high availability, data redundancy, load balancing, and disaster recovery.
Common use cases include:
- Scaling out reads across multiple servers
- Backup without affecting the master
- Real-time reporting or analytics
- Failover solutions in production systems
There are two main types:
- Asynchronous Replication: The master immediately continues processing after sending data to the replicas. Replicas may lag slightly behind the master depending on network and system speed. Ideal for systems where minor delays are acceptable.
- Semi-Synchronous Replication: The master waits for at least one replica to acknowledge receipt of data before committing the transaction. Provides better data consistency and lower risk of data loss in case of master failure. Slightly slower than asynchronous replication but more reliable for critical environments.