User Rating: 3 / 5

Star ActiveStar ActiveStar ActiveStar InactiveStar Inactive
 

1) Prepare the slave

2) Prepare the master, copy databases and restart master

3) Restart Replication Slave


1) Prepare the slave
SSH into the slave server.
Log into MySQL on the slave as root
mysql>STOP SLAVE;
mysql>RESET SLAVE;
mysql> exit;

Now exit and shutdown slave
# service mysql stop

Delete the databases on slave (DANGER ... this deletes ALL databases on slave)
# cd  /var/lib/mysql/

#rm -rf *

2) Prepare the master, copy databases and restart master
SSH into the master as root
log into mysql as root

Check users and kick them all off if more than yourself is connected
mysql> show processlist;
mysql> FLUSH TABLES WITH READ LOCK;
mysql> RESET MASTER;

exit and shutdown immediately
# service mysql stop

Now copy all the data from this master to the slave (may take a while)
# cd  /var/lib/mysql/
# scp -r * root@10.10.4.11:/var/lib/mysql/
(wait for password prompt)

Note: If you have a really huge amount of data and you have the drive space, it may be faster to make a local copy of the data directory on the master which can be then copied to the slave after you have restarted the master.

When copying is done, restart the master
#service mysql start

Log into master and make sure it is logging.
mysql> show master status\G
*************************** 1. row ***************************
File: binary-log.002
Position: 280
Binlog_do_db:
Binlog_ignore_db:
1 row in set (0.00 sec)

Make sure Position is increasing if insert and update activity is taking place on master.

Now you can breathe for a while!

3) Restart Replication Slave
Log into slave server and fix privileges on the data folder
# /var/lib/mysql/
# sudo chown -R mysql:mysql *

Restart server
#service mysql start

Log into mysql as root
#mysql
mysql> CHANGE MASTER TO MASTER_HOST='10.10.4.10',MASTER_USER='salveuser',MASTER_PASSWORD='yourpassword';
mysql>start slave;
mysql> SHOW SLAVE STATUS\G;
mysql>UNLOCK TABLES;

Verify that it is replicating and you are done.