Home > Support > HOWTO List > MySQL replication

MySQL replication

MySQL replication sets up master and slave databases.  The slave database keeps itself sychnonized with the master database in near real time.

Setting Up MySQL replication

In the master server [mysqld] section of /etc/my.cnf you should have something like:


[mysqld]
server-id=1
log-bin
# so user changes do not replicate to the slaves
replicate-ignore-db=mysql
log-warnings
log-slave-updates
skip-bdb

On the master server run:


GRANT REPLICATION SLAVE ON *.* TO 
mysql_slave@slaveserverip identified by 'somepassword'

In the slave MySQL server's /etc/my.cnf file you should have something like:


server-id       = 2
log-bin

Note that the server ids need to be unique for all the servers in your mysql replication cluster.

On the master server run:

SHOW MASTER STATUS

.

On the slave server's MySQL client use some of the values from that command to run the following:


CHANGE MASTER TO MASTER_HOST='masterserverip'
, MASTER_USER='mysql_slave',  MASTER_PASSWORD='somepassword'
, MASTER_LOG_FILE='logfilenameperabove-bin.000003'
, MASTER_LOG_POS=perabove;

SLAVE START;

Hosting

Why RimuHosting

RimuHosting