On the master (192.168.26.6)
Creating a User for Replication
mysql> create user ‘repl’ identified by ‘slavepass’;
mysql> grant replication slave on *.* to ‘repl’;
Setting the Replication Master Configuration
Stop the MySQL servive and add the following two lines into the mysqld section of the /etc/my.cnf file.
After changing, start the mysql service.
Obtaining the Replication Master Binary Log Coordinates
Flush all tables and block write statements
mysql> FLUSH TABLES WITH READ LOCK;
The File column shows the name of the log file and Position shows the position within the file. Record these values. We need them later when we are setting up the slave.
Creating a Data Snapshot Using mysqldump
# mysqldump -uroot -ppassword –all-databases –lock-all-tables > dbdump.db
After creating the snapshot, unlock the tables in the terminal running “FLUSH” command
mysql> UNLOCK TABLES;
On the slave (192.168.26.67)
Setting the Replication Slave Configuration
Stop the MySQL servive and add the following line into the mysqld section of the /etc/my.cnf file.
Then start the server using the –skip-slave-start option so that replication does not start.
# service mysqld start –skip-slave-start
Import the dump file
Copy the dbdump.db file from the master server to local, and then import the dump file
# mysql -u root -p < dbdump.db
Setting the Master Configuration on the Slave
mysql> change master to
Start the slave
mysql> start slave;
From the image, we can see “Slave_IO_Running: Yes” and “Slave_SQL_Running: Yes”. It indicates that the replication is normal.
We also can run “show master status” at the master server and “show slave status\G” at the slave server repeatedly to compare “Position” with “Read_Master_Log_Pos”, we will find they are generally approaching.