Welcome to our comprehensive guide on MySQL Replication! This tutorial is designed to help you understand and implement MySQL replication from scratch, making it suitable for both beginners and intermediate learners. 📝
MySQL replication is a method of copying data from a master database server to one or more slave database servers. It's a powerful feature that enables you to maintain multiple identical copies of the database, ensuring data availability, improving performance, and providing disaster recovery options.
my.cnf or my.ini).sudo nano /etc/mysql/my.cnfserver-id = 1
log_bin = mysql-binsudo service mysql restartsudo nano /etc/mysql/my.cnfserver-id = 2
replicate-donald-dbReplace donald-db with the name of the database you want to replicate.
sudo service mysql restartOn the slave server, execute the following command:
CHANGE MASTER TO
MASTER_HOST='master_ip',
MASTER_USER='replication_user',
MASTER_PASSWORD='replication_password',
MASTER_LOG_FILE='mysql-bin.000001',
MASTER_LOG_POS=4;Replace master_ip with the IP address of the master server, replication_user and replication_password with the credentials for the replication user.
START SLAVE;To check if replication is working, execute the following command on the slave server:
SHOW SLAVE STATUS\G;If the output shows that the slave is running and seconds_behind_master is 0, then replication is working correctly.
What is MySQL replication used for?
What is the role of the master server in MySQL replication?
What is the role of the slave server in MySQL replication?