0

Rebuilding an existing slave from a master using cold-copying of /var/lib/mysql, would this be the proper process/order? Anything missing?

  1. master mysql> SHOW MASTER STATUS\G (take notes)
  2. slave mysql> STOP SLAVE;
  3. Shut down master and slave mysqld
  4. Move existing slave:/var/lib/mysql out of the way
  5. Copy master:/var/lib/mysql to slave:/var/lib/mysql
  6. Start master mysqld
  7. Start slave mysqld
  8. slave mysql> CHANGE MASTER TO MASTER_HOST='masterserver',
    -> MASTER_USER='replicationusername',
    -> MASTER_PASSWORD='replcationpassword',
    -> MASTER_LOG_FILE='logfilefromshowmasterstatus',
    -> MASTER_LOG_POS=positionfromshowmasterstatus;
  9. slave mysql> start slave;
Chris Weiss
  • 25
  • 1
  • 6
  • There will be some time between "SHOW MASTER STATUS" and shutting down mysqld. Might I suggest using "FLUSH TABLES WITH READ LOCK;" then "SHOW MASTER STATUS;" (Take notes). FLUSH tables will make sure all changes are written to disk and with read lock will make sure the database does not change afterward. – racyclist Oct 13 '10 at 21:11
  • Here are step by step instruction how to do this with minimal downtime using Linux LVM snapshots. http://www.juhavehnia.com/2015/05/rebuilding-mysql-slave-using-linux-lvm.html – Juha Vehnia May 20 '15 at 19:07

3 Answers3

0

I'd suggest referring to a following link:

MySQL MySQL 5.1 Reference Manual 16.1.1 How to Set Up Replication

alexus
  • 12,342
  • 27
  • 115
  • 173
0

Other pieces to add to the mix:

step 6.5 Check permissions after moving files

Step 7 - restart slave with mysqld_safe --skip-slave-start &

Chris Weiss
  • 25
  • 1
  • 6
0

1.- Stop master and slave mysqld.

2.- On slave move /var/lib/mysq/ to someplace else.

3.- Copy /var/lib/mysql from master to slave.

4.- Check permissions on slave.

5.- On slave (/etc/my.cnf) set --skip-slave-start

6.- Start master and slave mysqld

7.- On slave point to the new master binlog file just created, on position 4.

8.- start slave io_thread, then see if everything is okay

9.- start slave sql_thread and wait the slave to get up to date.

That's it.

CarlosH
  • 413
  • 2
  • 5
  • 9