In the recent past, for a variety of reasons, I occasionally had to change the IP address of a MySQL master in a replicated environment.
It was a major annoyance that it was not sufficient to just change the IP address in the MySQL configuration file for slaves and then restart the server. Instead, I basically had to start from scratch, setting up replication anew. There had to be an easier way.
Well, there is. What you basically need to do is ensure that the slave is fully caught up (to the point when it was disconnected from the master). Then, stop the slave, adjust slave parameters, and restart.
Which parameters, you ask? Well, the address of the master, the name of the master log file, and the position within the file. The latter two can be obtained by viewing the slave status:
mysql> SHOW SLAVE STATUS\G
*************************** 1. row ***************************
Slave_IO_State: Reconnecting after a failed master event read
1 row in set (0.00 sec)
The next step is to stop the slave:
mysql> STOP SLAVE;
Next comes the aforementioned change of replication parameters, which can be accomplished by issuing the following command:
mysql> CHANGE MASTER TO MASTER_HOST='192.168.1.1',
The value of MASTER_HOST is, of course, the new IP address of the master. The MASTER_LOG_FILE and MASTER_LOG_POS values come from the output SHOW SLAVE STATUS command above.
Finally, restart the slave:
mysql> START SLAVE;
That’s it. Do verify though that the slave is working properly by reissuing the SHOW SLAVE STATUS command a few times, watching as the slave catches up with the master.