以前一般是两个子集群,在写数据时,两个子集群都写。偶然在网上看到双机互为主从的实现,感到有点意思,于是体验一下,感觉还是不错的,特别是数据量较少时,不失为一种防止单点故障的方案。
第一步授权
主:192.168.237.134
create database abc;
create table cc(id int, name varchar(20),age int);
grant replication slave on *.* to ‘root’@’192.168.237.133’identified by ‘123456’;
flush privileges;
主:192.168.237.133
create database abc;
create table cc(id int, name varchar(20),age int);
grant replication slave on *.* to ‘root’@’192.168.237.134’identified by ‘123456’;
flush privileges;
第二步 my.conf文件配置[mysqld]段:
主:192.168.237.134
server-id= 1
binlog-do-db=abc #多个数据库,可重复添加,如果没有设置,则所有数据库。
binlog-do-db=abc
binlog-ignore-db = mysql
master-host=192.168.237.133
master-user=root
master-password=123456
master-port=3306
master-connect-retry=60
log-bin
主:192.168.237.133
server-id= 2
binlog-ignore-db = mysql
master-host=192.168.237.134
master-user=root
master-password=123456
master-port=3306
master-connect-retry=60
replicate-do-db=abc
binlog-do-db=abc
log-bin