MySQL-主从配置

 

1. 配置同步账号

create user 'sync'@'192.168.10.%' identified by 'sync';
grant replication slave on *.* to 'sync'@'192.168.10.%';
flush privileges;

2. 开启binlog

# /etc/my.cnf增加一下配置
# open binary log mode
log_bin = /mydata/binlog
binlog-format = ROW

3. 初始化

mysqldump --single-transaction -uroot -hmaster -P3308 --master-data=2 -A |mysql -uroot -hslave -P3308

4. 配置主从同步

mysql -uroot -hmaster -P3308 -e " CHANGE MASTER TO MASTER_HOST='192.168.10.181', MASTER_USER='sync', MASTER_PASSWORD='sync', MASTER_PORT=3306; "

5. 启动服务

-- 开启主从
start slave;

6. 检查确认

show slave status\G;
show master status\G;
posted @ 2020-03-19 12:36  KuBee  阅读(195)  评论(0编辑  收藏  举报