3

Quick questions about MySQL Master-Slave-Slave set-ups:

I currently have a Master-Slave set up right now and I would like to add another slave. Would it be possible to clone the server running the slave, and then spin up a new server with the image from the slave, and have it pick up right where it left off? So whatever the binlog was at the time of the copy it would just run until it catches up with the master?

Ideally - I'm trying to start another slave the connects to the master without shutting down the Master for a backup. Any advice or guidance would be great. Thanks!

gregavola
  • 2,289
  • 4
  • 29
  • 44
  • 1
    You may want to consider asking questions like this on [DBA.SE](http://dba.stackexchange.com/), they probably have more knowledge of non-trivial MySQL setups. – derobert Aug 15 '12 at 16:09

4 Answers4

4

Yes, you can shutdown slave instance, and copy all it's data to another slave (including logs).
Don't forget to edit my.cnf on second slave (you should change server-id)
Then start both slave servers

CyberDem0n
  • 13,057
  • 1
  • 29
  • 21
  • And it will just pick up where it left off before "shutting it down"? When you say "shut it down", I assume you stop the Slave from reading from the logs (or stop master-slave communication), right? – gregavola Aug 15 '12 at 16:11
  • 1
    when you shut down slave instance, it stops reading logs too. so all data would be consistent – CyberDem0n Aug 15 '12 at 16:15
2

Yes this is possible. The best way would probably be to temporarily pause the replication on the slave, determine the master binary log position information, then make your dump from the replica while replication is still paused (and no other data is changing on the replica). After the dump is complete you can restart the replica.

On the new server, just install the dump, set the binlog coordinates and start up the replication. A word of caution though. Make sure your settings for purging the binary logs on the master will allow for retention of the binary logs for long enough for you to do this set up process and get the new slave caught up before the bin logs are purged.

Mike Brant
  • 66,858
  • 9
  • 86
  • 97
  • 1
    I think he's asking if he can take a literal snapshot of his active MySQL slave, boot that up, and have it act as though it starts where the snapshot was taken (to avoid having to do a data dump and reload it) – Michael Aug 15 '12 at 16:07
0

Here's a good tutorial on how to setup multiple replication slaves for a master server: http://arcib.dowling.edu/cgi-bin/info2html?%28mysql%29replication-howto

It doesn't explain your scenario, but gives important hints: you must assign a unique server-id to your second slave.

Regarding your problem: If your masters binary log is kept long enough, you should not get into trouble. Just shutdown your slave for a moment, clone it and write down: MASTER_LOG_FILE and MASTER_LOG_POS of the slave; then restart the original slave and setup the second slave correctly: that means with that given MASTER_LOG_POS and *_FILE set and a unique server-id in my.cnf;

Then start up your second slave. Use "START SLAVE" to start the replication and then have a look at "SHOW SLAVE STATUS;"

Regards, Stefan

PS: Cannot promise this to work, but I'm quit sure it should do.

SDwarfs
  • 3,074
  • 5
  • 23
  • 52
0

You can use existing mysql slave to make a new one just do the following steps,

  1. Stop replication on slave.
  2. execute show slave status; and note these values Master_Log_File: master-bin.000002 & Read_Master_Log_Pos: 1307
  3. Take mysqldump and restore it on new mysql slave server, you can copy my.cnf file from existing mysql slave server and just change server-id.
  4. execute change master to command on new slave server providing details of mysql master server and log file name and log position which we obtained from existing mysql slave.
  5. execute start slave; on existing mysql slave.
  6. to verify slave status run show slave status.

that's it you have a new mysql slave server!!

Good luck !

Shoaib
  • 102
  • 1
  • 13