mysql 主从复制流程图
Server version: 10.0.24-MariaDB-7 Ubuntu 16.04
- Master 记录二进制文件
- 导出数据并记录二进制位置
- 导入数据,设置二进制位置,并开启同步
具体配置流程
1.打开Master二进制记录功能
[mysqld]
server_id = 132
log_bin = /var/log/mysql/mysql-bin.log
2.授权Slave 锁表 并记录二进制位置
grant replication slave on *.* to "rep128E"@"192.168.110.128" identified by "123456";
FLUSH TABLES WITH READ LOCK;
SHOW MASTER STATUS\G;
3.导出表并传递到Slave
mysql -u root -p < backup.sql;
scp backup.sql root@192.168.110.128:/var/tmp/backup.sql
4.解锁Master
unlock tables;
5.导入数据并设置二进制文件同步点
mysql -u root -p < backup.sql;
CHANGE MASTER TO MASTER_HOST=‘192.168.110.132‘, MASTER_USER=‘rep128‘, MASTER_PASSWORD=‘123456‘, MASTER_LOG_FILE=‘mysql-bin.000001‘, MASTER_LOG_POS=508;
6.开启同步并查看状态
start slave;
SHOW SLAVE STATUS\G;