Tag Archives: MySQL

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

centos 7 mysql 5.7

yum install https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm -y

yum repolist enabled | grep “mysql.*-community.*”
mysql-connectors-community/x86_64 MySQL Connectors Community 165
mysql-tools-community/x86_64 MySQL Tools Community 115
mysql57-community/x86_64 MySQL 5.7 Community Server 444

systemctl start mysqld
grep ‘temporary password’ /var/log/mysqld.log
2020-08-08T18:56:50.367913Z 1 [Note] A temporary password is generated for root@localhost: xxxxxxxxxxxxx