5

I have one master and one slave replicating great, but the master is about to have both it's hostname and IP changed. In master.info on the slave server I see the current hostname for the master, if I shutdown the slave server, change the hostname in that file and then restart MySQL will that be all I need? No usernames/passwords etc are changing.

If I used CHANGE MASTER queries instead it looks like it will require re-setting the binlog position etc?

1 Answer 1

6

Once you change the MASTER_HOST, everything else needs to change with it.

The "dark back-alley" approach you just suggested is exactly what to do.

Warning: Some systems use "mysqld" versus "mysql". 
The --skip-slave-restart "option" may not available without editing your
/etc/init.d/mysqld script to include this as a new option. 
If used, it will still start the slave upon startup.</p>

On the Slave, run these four lines:

cd /var/lib/mysql  
service mysql stop  
cp master.info master.info.bak
wc -l < master.info

The last line echoes the number of lines in master.info

Next, vi master.info and change the IP address.

Next, run wc -l < master.info and make sure the linecount is still the same

Next, start mysql without starting replication

service mysql start --skip-slave-start

Login to MySQL, and run

SHOW SLAVE STATUS\G

If the IP address you added appears, then run

START SLAVE; SELECT SLEEP(5);
SHOW SLAVE STATUS\G

If you see Slave_IO_Running : Yes and Slave_SQL_Running : Yes, Congratulations !!!

Give it a Try !!!

2
  • 2
    Hey i was reading this linuxsysadminblog.com/2008/07/… Why not doing it like this? STOP SLAVE; SHOW SLAVE STATUS; Master_Log_File: mysql-bin.000101 Read_Master_Log_Pos: 591523680 CHANGE MASTER TO MASTER_HOST='NEW IP ADDRESS', MASTER_LOG_FILE='mysql-bin.000101', MASTER_LOG_POS=591523680; START SLAVE;
    – bicycle
    Feb 24, 2014 at 11:13
  • 1
    FOR anyone trying to be lazy: If you specify the MASTER_HOST or MASTER_PORT option, the slave assumes that the master server is different from before, the old values for the master binary log file name and position are considered no longer applicable
    – Jerry Chin
    Aug 26, 2019 at 3:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.