If you want to add another slave to the existing replication configuration then you can do so without stopping the master. Instead, you duplicate the settings on the slaves by making a copy of one of the slaves.
To duplicate the slave:
Shut down the existing slave:
shell> mysqladmin shutdown
Copy the data directory from the existing slave to the new
slave. You can do this by creating an archive using
tar or WinZip, or by
performing a direct copy using a tool such as
cp or rsync. Ensure
that you also copy the log files and relay log files.
A common problem that is encountered when adding new replication slaves is that the new slave fails with a series of warning and error messages like these:
071118 16:44:10 [Warning] Neither --relay-log nor --relay-log-index were used; so replication may break when this MySQL server acts as a slave and has his hostname changed!! Please use '--relay-log=new_slave_hostname-relay-bin' to avoid this problem. 071118 16:44:10 [ERROR] Failed to open the relay log './old_slave_hostname-relay-bin.003525' (relay_log_pos 22940879) 071118 16:44:10 [ERROR] Could not find target log during relay log initialization 071118 16:44:10 [ERROR] Failed to initialize the master info structure
This is due to the fact that, if the
--relay-log option is not specified, the
relay log files contain the hostname as part of their
filenames. (This is also true of the relay log index file
if the --relay-log-index option is not
used. See Section 15.1.3, “Replication Options and Variables”, for more
information about these options.)
To avoid this problem, use the same value for
--relay-log on the new slave that was
used on the existing slave. (If this option was not set
explicitly on the existing slave, use
.)
If this is not feasible, then copy the existing
slave's relay log index file to the new slave and set
the existing_slave_hostname-relay-bin--relay-log-index option on the new
slave to match what was used on the existing slave. (If
this option was not set explicitly on the existing slave,
use
.)
Alternatively — if you have already tried to start
the new slave (after following the remaining steps in this
section) and have encountered errors like those described
previously — then perform the following steps:
existing_slave_hostname-relay-bin.index
If you have not already done so, issue a
STOP SLAVE on the new slave.
If you have already started the existing slave
again, issue a STOP SLAVE on the
existing slave as well.
Copy the contents of the existing slave's relay log index file into the new slave's relay log index file, making sure to overwrite any content already in the file.
Proceed with the remaining steps in this section.
Copy the master.info and
relay.info files from the existing
slave to the new slave. These files hold the current log
positions.
Start the existing slave.
On the new slave, edit the configuration and the give the
new slave a new unique server-id.
Start the new slave; the master.info
file options will be used to start the replication process.


User Comments
I found that this does not work on 5.0... (maybe it does on 5.1)
The problem is that the relay log have the name of the old slave. I worked around it with a combination of using mysqlbinlog on the old slave's relay log, and a CHANGE MASTER TO statement to correctly set the new slave master info.
See Christine Korza's comment on mysqlbinlog on:
http://dev.mysql.com/doc/refman/5.0/en/replication.html
So, what i did now:
- get a copy of old slave
- move master.info and relay-log.info to backup
- start new slave with skip-slave option in my.cnf
- feed old slave relay log to new slave using mysqlbinlog (use info from relay-log.info.oldslave)
- use CHANGE MASTER TO using info from master.info.oldslave
- START SLAVE
- remove skip-slave option from my.cnf
That should do it...
Add your own comment.