资讯

展开

mysql5.5.62主主同步

作者:快盘下载 人气:

mysql5.5.62主主同步

192.168.11.122 mysql01
192.168.11.124 mysql02
配置双主mysql同步的关键点是server-id需要不同,还有需要配置mysql01和mysql02
mysql01的my.cnf配置需要添加:

server-id=1
log_bin = mysql-bin
auto_increment_offset=1
auto_increment_increment=2
#需要同步的数据库
replicate-do-db=zabbix
replicate-do-db=wordpress
replicate-do-db=elk
replicate-ignore-db=mysql
replicate-ignore-db=information_schema
replicate-ignore-db=performance_schema

mysql02的my.cnf配置需要添加:
server-id=2
log_bin = mysql-bin
auto_increment_offset=2
auto_increment_increment=2
#需要同步的数据库
replicate-do-db=zabbix
replicate-do-db=wordpress
replicate-do-db=elk
#不需要同步的数据库
replicate-ignore-db=mysql
replicate-ignore-db=information_schema
replicate-ignore-db=performance_schema


启动mysql01,mysql02然后添加repl账号用于数据库信息同步:

#test01
grant replication slave on *.* to 'repl'@'192.168.11.%' identified by '123456';
flush privileges;

#test02
grant replication slave on *.* to 'repl'@'192.168.11.%' identified by '123456';
flush privileges;

#test01查看binlog位置
show master status;
"mysql-bin.000007"  "335"   ""  ""

#test02查看binlog位置
show master status;
"mysql-bin.000008"  "345"   ""  ""


互相设置对方为master,然后启动slave,再查看slave状态进行确认。(Slave_IO_Running: Yes ,Slave_SQL_Running: Yes)

#test01
change master to master_host='192.168.11.124',master_port=3306,master_user='repl',master_password='123456',master_log_file='mysql-bin.000008',MASTER_LOG_POS=345;
start slave;
show slave status;

#test02
change master to master_host='192.168.11.122',master_port=3306,master_user='repl',master_password='123456',master_log_file='mysql-bin.000007',MASTER_LOG_POS=335;
start slave;
show slave status;


最后登录数据库创建数据库进行对比测试即可。

加载全部内容

相关教程
猜你喜欢
用户评论
快盘暂不提供评论功能!