master /etc/my.cnf configuration:
server-id=1
relay-log = /var/lib/mysql/mysql-relay-bin
relay-log-index = /var/lib/mysql/mysql-relay-bin.index
log-error = /var/lib/mysql/mysql.err
master-info-file = /var/lib/mysql/mysql-master.info
relay-log-info-file = /var/lib/mysql/mysql-relay-log.info
log-bin = /var/lib/mysql/mysql-bin
slave /etc/my.cnf configuration:
server-id=2
relay-log = /var/lib/mysql/mysql-relay-bin
relay-log-index = /var/lib/mysql/mysql-relay-bin.index
restart mysql on the master:
service mysqld restart
stop mysql on the slave:
service mysqld stop
on the master grant privileges to the slave:
GRANT REPLICATION SLAVE ON *.* TO ‘user’@'host’ IDENTIFIED BY ‘pass’;
on the master lock the database:
FLUSH TABLES WITH READ LOCK;
on the master take note of the current position and log file name:
SHOW MASTER STATUS \G
copy the data from the master to the slave
rsync -e ssh -av /var/lib/mysql/ root@host:/var/lib/mysql
on the master unlock the database:
UNLOCK TABLES;
fire up mysql on the slave:
service mysqld start
on the slave configure the master:
CHANGE MASTER TO
MASTER_HOST=’master_host’,
MASTER_USER=’user’,
MASTER_PASSWORD=’pass’,
MASTER_LOG_FILE=’log_file_name’,
MASTER_LOG_POS=log_position;
on the slave fire up the replication:
SLAVE START;
check on the slave status:
SHOW SLAVE STATUS \G
rejoice.
test it out – create tables, drop a database, do whatever you like on the master and watch the magic on the slave.