架构图:
Master配置:
1、开启二进制日志
log_bin=/var/lib/mysql/log_bin
binlog_format=MIXED
2、修改server-id
server-id=1
3、建立授权账号
grant replication slave on *.* to ‘repl’@’192.168.0.20’ identified by ‘123456’;
4、查看数据库状态
show master status;
查看binlog文件和position
slave1配置:
1、开启二进制日志
log_bin=/var/lib/mysql/log_bin
binlog_format=MIXED
log_slave_updates=1 #必须要有此参数,否则不会记录binlog日志
2、修改server-id
server-id=2
3、建立授权账号
grant replication slave on *.* to ‘repl2’@’192.168.0.30’ identified by ‘123456’;
4、查看数据库状态
show master status;
slave2配置
1.关闭二进制日志
2.修改server-id
3.执行同步
写入脚本
mysql<< EOF
change master to
master_host=’192.168.0.20′,
master_port=3306,
master_user=’repl2′,
master_password=’123456′,
master_log_file=’log_bin.000005′,
master_log_pos=446;
EOF
原创文章,作者:dweifng,如若转载,请注明出处:https://blog.ytso.com/273846.html