MySQL Replication Switch Master/Slave

It is good idea to turn of MySQL server at start. So that if the master goes down it does not start by itself when it comes back up.

Follow these steps on the slave :

Note: The Slave also has to be setup with binary logging enabled. In order to this you can add the following line to your my.cnf file :

log-bin = /var/lib/mysql/name-bin

  1. Login to msyql

  2. Stop Slave;

  3. Reset Master;

  4. Show master status \G;

Note the binary log position and the name on the result. This will be needed on the slave.

On the Master :

  1. Start mysql

  2. Login to mysql

3.Slave stop;

  1. CHANGE MASTER TO MASTER_HOST=’masterservername or ip’, MASTER_LOG_FILE=’binarylogname’, MASTER_LOG_POS=’binarylogposition from step 4 above’;

4.Slave start;

It is also good idea to clear the logfiles on slave.

cd /var/lib/mysql

rm relay

rm master.info