mysql master slave replication


log-bin=mysql-bin
server-id=1
innobackupex --user=root --password=password /path/to/backupdir
innobackupex --user=root --password=password --apply-log /path/to/backupdir/$TIMESTAMP/

GRANT REPLICATION SLAVE ON *.* TO 'repl'@'remote_ip' IDENTIFIED BY 'slave_password';

server-id=2
cat /var/lib/mysql/xtrabackup_binlog_info
mysql-bin.000001 100
CHANGE MASTER TO MASTER_HOST='master_ip', MASTER_USER='repl', MASTER_PASSWORD='slave_password', MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=100;
START SLAVE;

mysql> SHOW SLAVE STATUS \G
...
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
...
Seconds_Behind_Master: 13

Adding another slave, run on slave:
innobackupex --user=root --password=password --slave-info /path/to/backupdir
innobackupex --apply-log --use-memory=2G /path/to/backupdir/$TIMESTAMP/

On master:
GRANT REPLICATION SLAVE ON *.* TO 'repl2'@'new_slave_ip' IDENTIFIED BY 'new_slave_pass';

cat /var/lib/mysql/xtrabackup_binlog_info
mysql-bin.000001 100
CHANGE MASTER TO MASTER_HOST='master_ip', MASTER_USER='repl2', MASTER_PASSWORD='new_slave_password', MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=100;
START SLAVE;

skip-slave-start
server-id=3

Use sshfs or rsync to move data

Leave a Reply

Your email address will not be published. Required fields are marked *