MySQL - Moving slave

IF you want to make this a slave of sibling (cloned machine)


First you need to stop both slaves at the same spot in replication. Usually I am making a clone and just have the current state of the clone that I want to be the master. This is also assuming that you have master info setup in your mysql config so that it can be a master and you have the master_user and master_password setup already!!

on the original server - the new master - current sibling

  • find the master info
    show master status\G
  • save the output for later. example...
 mysql> show master status\G
 *************************** 1. row ***************************
              File: {FILENAME}
          Position: {POSITION}
      Binlog_Do_DB:
  Binlog_Ignore_DB:
 Executed_Gtid_Set:
 1 row in set (0.00 sec)

on the sibling - new slave - cloned machine

 RESET SLAVE;
 CHANGE MASTER TO MASTER_HOST='{MASTER HOSTNAME}', MASTER_LOG_FILE='{FILENAME}', MASTER_LOG_POS={POSITION};


Moving slave to be a sibling. (same master) 

aka: moving a slave up to be a sibling of it's current master

on the master server
  • find the master info
    stop slave\G
    show slave status\G
  • save the output for later. example...
 mysql> show slave status\G
*************************** 1. row ***************************
               Slave_IO_State:
                  Master_Host: bin-mysql1.usi.ben
                  Master_User: replicator
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: binarylogs.000294
          Read_Master_Log_Pos: 1023912681
               Relay_Log_File: mn-mysql2b-relay-bin.000878
                Relay_Log_Pos: 1023912845
        Relay_Master_Log_File: binarylogs.000294
             Slave_IO_Running: No
            Slave_SQL_Running: No
              Replicate_Do_DB:
          Replicate_Ignore_DB:
           Replicate_Do_Table:
       Replicate_Ignore_Table:
      Replicate_Wild_Do_Table:
  Replicate_Wild_Ignore_Table: broker_history.%,ic_history.%
                   Last_Errno: 0
                   Last_Error:
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 1023912681
              Relay_Log_Space: 1023913071
              Until_Condition: None
               Until_Log_File:
                Until_Log_Pos: 0
           Master_SSL_Allowed: No
           Master_SSL_CA_File:
           Master_SSL_CA_Path:
              Master_SSL_Cert:
            Master_SSL_Cipher:
               Master_SSL_Key:
        Seconds_Behind_Master: NULL
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error:
               Last_SQL_Errno: 0
               Last_SQL_Error:
  Replicate_Ignore_Server_Ids:
             Master_Server_Id: 131
                  Master_UUID: 1440fc1b-1d03-11e5-8ab5-0050568abe39
             Master_Info_File: /mnt/mysql/master.info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State:
           Master_Retry_Count: 86400
                  Master_Bind:
      Last_IO_Error_Timestamp:
     Last_SQL_Error_Timestamp:
               Master_SSL_Crl:
           Master_SSL_Crlpath:
           Retrieved_Gtid_Set:
            Executed_Gtid_Set:
                Auto_Position: 0

on the clone
!!!the key here is to make sure this slave is zero(0) seconds behind master!!!!
 STOP SLAVE;
USE Relay_Master_Log_File:Exec_Master_Log_Pos
 CHANGE MASTER TO MASTER_HOST='{MASTER HOSTNAME}', MASTER_LOG_FILE='{Relay_Master_Log_File}', MASTER_LOG_POS={Exec_Master_Log_Pos};
 START SLAVE;

on the original master server
  • restart slave - this can be done as soon as the slave is caught up and stopped.
    start slave;

Useful Links

https://www.percona.com/blog/2008/07/07/how-show-slave-status-relates-to-change-master-to/
http://blog.remibergsma.com/2012/07/10/moving-a-mysql-slave-to-a-new-replication-master/

Popular Posts