Instructions for setting up MySQL Replication
SYNOPSIS
- This documentation assumes two functional MySQL servers that are new enough
to support replication. Links to some binary/source RPM packages for RedHat
Linux can be found here. It is preferred that your MySQL servers be identical
versions.
PREPARATION OF MASTER SERVER
- Select a master server. It can be either one.
- Make sure all databases that you want to replicate to the slave already
exist! The easist way is to just copy the database dirs inside your MySQL
data directory intact over to your slave, and then recursively chown
them to "mysql:mysql". Remember, the binary structures are file-system
dependant, so you can't do this between MySQL servers on different OS's.
In this instance you will want to use mysqldump most likely.
- Create /etc/my.cnf if you do not already have one:
[mysqld]
socket=/tmp/mysql.sock [enter YOUR path to mysql.sock here]
server-id=1
log-bin
- Permit your slave server to replicate by issuing the following SQL
command (substituting your slave's IP and preferred password):
mysql> GRANT FILE ON *.* TO replicate@192.168.1.2 IDENTIFIED BY 'somepass';
- Shut down and restart MySQL daemon and verify that all is functional.
PREPARATION OF SLAVE
- Create /etc/my.cnf if you do not already have one:
[mysqld]
socket=/tmp/mysql.sock [enter YOUR path to mysql.sock here]
server-id=2 [MUST be different to master]
master-host=192.168.1.1
master-user=replicate
master-password=somepass
- Shut down and restart MySQL on slave.
- Issue the following SQL command to check status:
mysql> show slave status;
TESTING
- Just update some data on the master, and query that record on the slave.
The update should be instantaneous.
NOTES
- Tested between two Solaris [2.6/7] machines running MySQL-3.23.28-gamma
and two RedHat Linux [6.2/7.0] machines running MySQL-3.23.28-i386.
- These instructions should be relatively easy, however if there are
any suggestions or noted ommissions/errors, etc. feel free to drop
me a note at bofh at ls dash l dot net
Colin Bloch [12/25/2000]