Professional Documents
Culture Documents
MySQL Replication: Setting Up A Simple Master / Slave
MySQL Replication: Setting Up A Simple Master / Slave
From : http://www.stardothosting.com
2. 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.
[mysqld]
socket=/tmp/mysql.sock [enter YOUR path to mysql.sock here]
server-id=1
log-bin=mysql-bin
binlog-do-db=bossdb # input the database which should be replicated
binlog-ignore-db=mysql1 # input the database that should be ignored for
replication
binlog-ignore-db=mysql2 # input the database that should be ignored for
replication
4. Permit your slave server to replicate by issuing the following SQL command
(substituting your slave’s IP and preferred password):
5. Shut down and restart MySQL daemon and verify that all is functional.
PREPARATION OF SLAVE
[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
This will manually start the slave process. Note that only updated tables and
entries after the slave process has started will be sent from the master to the
slave — it is not a differential replication.
TESTING
Just update some data on the master, and query that record on the slave. The
update should be instantaneous.
mysql> CREATE TABLE example4( id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(id),
name VARCHAR(30), age INT);
Query OK, 0 rows affected (0.04 sec)
And check the database on the slave to ensure that the recently created table on
the master was replicated properly.