主1 192.168.66.15
主2 192.168.66.16
主1:
root@test2 ~]# hostname master1
[root@test2 ~]# bash
[root@master1 ~]# vim /etc/my.cnf
server-id=11
log-bin=mysql-bin
auto_increment_increment=2
auto_increment_offset=1
replicate-do-db=demo_db
[root@master1 ~]# systemctl restart mysqld
[root@master1 ~]# mysql -u root -p123456
mysql> create user 'master1'@'%' identified with mysql_native_password by '123456';
Query OK, 0 rows affected (0.00 sec)
mysql> grant replication slave on *.* to 'master1'@'%';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> show grants for 'master1'@'%';
mysql> show master status;
主2:
[root@localhost ~]# hostname master2
[root@localhost ~]# bash
[root@master2 ~]# vim /etc/my.cnf
server-id=12
log-bin=mysql-bin
auto_increment_increment=2
auto_increment_offset=2
replicate-do-db=demo_db
[root@master2 ~]# systemctl restart mysqld
[root@master2 ~]# mysql -uroot -p123456
mysql> change master to master_host='192.168.66.25',
-> master_user='master1',
-> master_password='123456',
-> master_log_file='mysql-bin.000001',
-> master_log_pos=768;
start slave;
show slave status \G
mysql> create user 'master2'@'%' identified with mysql_native_password by '123456';
Query OK, 0 rows affected (0.00 sec)
mysql> grant replication slave on *.* to 'master2'@'%';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> show master status;
主1:
mysql> change master to master_host='192.168.66.16',
-> master_user='master2',
-> master_password='123456',
-> master_log_file='mysql-bin.000001',
-> master_log_pos=768;
start slave;
show slave status \G
主1:
create database demo_db;
use demo_db;
主2:
主2
use demo_db;
create table test(id int(4));
主1: