mysql主从驱动_mysql主从同步

server1:

vim /etc/my.cnf

添加如下内容

server_id=1

gtid_mode=ON

enforce_gtid_consistency=ON

master_info_repository=TABLE

relay_log_info_repository=TABLE

binlog_checksum=NONE

log_slave_updates=ON

log_bin=binlog

binlog_format=ROW

transaction_write_set_extraction=XXHASH64

loose-group_replication_group_name="5b7af891-9c7c-11e8-b12d-525400b7366b"

loose-group_replication_start_on_boot=off

loose-group_replication_local_address= "172.25.8.1:24901"

loose-group_replication_group_seeds="172.25.8.1:24901,172.25.8.2:24902,172.25.8.3:24901"

loose-group_replication_bootstrap_group= off

loose-group_replication_single_primary_mode=off

loose-group_replication_enforce_update_everywhere_checks=on

loose-group_replication_ip_whitelist="172.25.8.0/24,127.0.0.1/8"

/etc/init.d/mysqld  start

grep  password /var/log/mysql.log

mysql  -p

在库中执行操作

mysql>set sql_log_bin=0;

mysql>alter user root@localhost identified by 'Westos-123';

mysql>grant replication slave on *.* to rpl_user@'%' identified by 'Westos-123';

mysql> flush privileges;

mysql> reset master;

mysql> set sql_log_bin=1;

mysql> change master to master_user='rpl_user',master_password='Westos-123' for channel 'group_replication_recovery';

mysql> INSTALL PLUGIN group_replication SONAME 'group_replication.so';

mysql> SHOW PLUGINS;

mysql> SET GLOBAL group_replication_bootstrap_group=ON;

mysql> START GROUP_REPLICATION;

mysql> SELECT * FROM performance_schema.replication_group_members;

db7f6970d6ad2b990f9189b9b80cbefd.png

server2:

vim /etc/my.cnf

server_id=2

gtid_mode=ON

enforce_gtid_consistency=ON

master_info_repository=TABLE

relay_log_info_repository=TABLE

binlog_checksum=NONE

log_slave_updates=ON

log_bin=binlog

binlog_format=ROW

transaction_write_set_extraction=XXHASH64

loose-group_replication_group_name="64f38c0e-8ca8-4e48-940d-a6642e249e99"

loose-group_replication_start_on_boot=off

loose-group_replication_local_address= "172.25.8.2:24901"

loose-group_replication_group_seeds="172.25.8.1:24901,172.25.8.2:24902,172.25.8.3:24901"

loose-group_replication_bootstrap_group= off

loose-group_replication_single_primary_mode=off

loose-group_replication_enforce_update_everywhere_checks=on

loose-group_replication_ip_whitelist="172.25.8.0/24,127.0.0.1/8"

/etc/init.d/mysqld  start

mysql>grep  password /var/log/mysql.log

mysql>mysql  -p

mysql>set sql_log_bin=0;

mysql> alter user root@localhost identified by 'Xubowen+007';

mysql> grant replication slave on *.* to rpl_user@'%' identified by 'Xubowen+007';

mysql> reset master;

mysql> set sql_log_bin=1;

mysql> change master to master_user='rpl_user',master_password='westos-123' for channel 'group_replication_recovery';

mysql> INSTALL PLUGIN group_replication SONAME 'group_replication.so';

mysql> SHOW PLUGINS;

9685fe439e39f8c629d2a282510f1730.png

mysql> START GROUP_REPLICATION;

mysql> SELECT * FROM performance_schema.replication_group_members;

server3

vim /etc/my.cnf

server_id=3

gtid_mode=ON

enforce_gtid_consistency=ON

master_info_repository=TABLE

relay_log_info_repository=TABLE

binlog_checksum=NONE

log_slave_updates=ON

log_bin=binlog

binlog_format=ROW

transaction_write_set_extraction=XXHASH64

loose-group_replication_group_name="64f38c0e-8ca8-4e48-940d-a6642e249e99"

loose-group_replication_start_on_boot=off

loose-group_replication_local_address= "172.25.8.3:24901"

loose-group_replication_group_seeds="172.25.8.1:24901,172.25.8.2:24902,172.25.8.3:24901"

loose-group_replication_bootstrap_group= off

loose-group_replication_single_primary_mode=off

loose-group_replication_enforce_update_everywhere_checks=on

loose-group_replication_ip_whitelist="172.25.8.0/24,127.0.0.1/8"

/etc/init.d/mysqld  start

grep  password /var/log/mysql.log

mysql  -p

mysql> set sql_log_bin=0;

mysql> grant replication slave on *.* to rpl_user@'%' identified by 'Westos-123';

mysql> reset master;

mysql> set sql_log_bin=1;

mysql> change master to master_user='rpl_user',master_password='Westos-123' for channel 'group_replication_recovery';

mysql> INSTALL PLUGIN group_replication SONAME 'group_replication.so';

mysql> START GROUP_REPLICATION;

mysql> SELECT * FROM performance_schema.replication_group_members;

测试

server1中写入数据

mysql> create database test;

mysql> use test;

mysql> create table t1 (c1 int primary key,c2 text not null);

mysql> insert into t1 values(1,'luis');

server3可查看

283af1339601747b7751695f010f2b98.png

server2中写入数据

mysql> use test;

mysql> insert into t1 values(3,'lucy');

server3可查看

37cb6e9abfa046dca2208e5648cda33e.png

f7b325f6a98f3ea5d0bd816e6878195a.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值