MySQL replication is a critical feature for data redundancy, high availability, and scalability. Here's a concise overview:
📌 Types of Replication
Asynchronous Replication
- Master writes to binlog, slave fetches updates after some delay.
Semi-Synchronous Replication
- Ensures at least one slave acknowledges the transaction before committing on the master.
Synchronous Replication
- All slaves must acknowledge the transaction before it is considered committed.
🧰 Configuration Steps
Enable Binary Logging
- Modify
my.cnf
ormy.ini
:[mysqld] log-bin=mysql-bin server-id=1
- Modify
Create Replication User
- On the master:
CREATE USER 'repl'@'%' IDENTIFIED BY 'password'; GRANT REPLICATION SLAVE ON *.* TO 'repl'@'%';
- On the master:
Set Master Info
- On the slave:
CHANGE MASTER TO MASTER_HOST='master_ip', MASTER_USER='repl', MASTER_PASSWORD='password', MASTER_LOG_FILE='mysql-bin.0001', MASTER_LOG_POS=1234;
- On the slave:
Start Replication
- Execute:
START SLAVE;
- Execute:
Verify Status
- Check:
SHOW SLAVE STATUS\G
- Ensure
Slave_IO_Running
andSlave_SQL_Running
are bothYes
.
- Check:
📚 Further Reading
For detailed setup instructions, visit our MySQL Setup Guide.