MySQL主主
master1:
1)设置slave数据库的my.cnf配置文件
[root@node1 ~]# vim /etc/my.cnf server-id=1 log-bin=mysql-bin
2)配置数据库
mysql> grant replication slave,replication client,select on *.* to slave@'192.168.1.%' identified by 'Slave@123'; mysql> flush privileges; mysql> show master status; +------------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +------------------+----------+--------------+------------------+-------------------+ | mysql-bin.000003 | 154 | | mysql | | +------------------+----------+--------------+------------------+-------------------+ 3)指定master2 mysql> stop slave; mysql> charge master to master_host="192.168.1.200",master_user="slave",master_password="123456",master_log_file="mysql-bin.000004",master_log_pos=160; mysql> start slave; mysql> show slave status\G;
master2:
1)设置slave数据库的my.cnf配置文件
[root@node1 ~]# vim /etc/my.cnf server-id=2 log-bin=mysql-bin
2)配置数据库
mysql> grant replication slave,replication client,select on *.* to slave@'192.168.1.%' identified by 'Slave@123'; mysql> flush privileges; mysql> show master status; +------------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +------------------+----------+--------------+------------------+-------------------+ | mysql-bin.000004 | 160 | | mysql | | +------------------+----------+--------------+------------------+-------------------+
3)指定master1
mysql> stop slave; mysql> charge master to master_host="192.168.1.200",master_user="slave",master_password="123456",master_log_file="mysql-bin.000003",master_log_pos=154; mysql> start slave; mysql> show slave status\G;