当前位置: 移动技术网 > IT编程>数据库>Mysql > mysql MGR 单主多主模式切换知识点详解

mysql MGR 单主多主模式切换知识点详解

2020年05月12日  | 移动技术网IT编程  | 我要评论

闻道华东seo,美国非农数据公布时间,火影忍者h小樱pixxx

主库执行

create database test character set utf8 collate utf8_general_ci;
use test;
create table if not exists h1 (id int(10) primary key auto_increment,name varchar(50) not null);
insert into test.h1 values(1,"wang"),(2,"guo"),(3,"yang"),(4,"he");
select * from test.h1;

从库测试

delete from test.h1 where id>3;
error 1290 (hy000): the mysql server is running with the --super-read-only option so it cannot execute this statement

1、单主切换到多主模式

1.1、停止组复制(在所有mgr节点上执行):

stop group_replication;
set global group_replication_single_primary_mode=off;
set global group_replication_enforce_update_everywhere_checks=on;

1.2、随便某个mgr节点执行:186

set global group_replication_bootstrap_group=on;
start group_replication;
set global group_replication_bootstrap_group=off;

1.3、然后在其它mgr节点执行:194 195

start group_replication;

1.4、查看mgr组信息(任意mgr节点查看)

select * from performance_schema.replication_group_members;

可以看到所有mgr节点状态都是online,角色都是primary,mgr多主模式搭建成功。

验证下mgr多主模式的节点数据同步:

在mgr-node1节点更新数据:

在mgr-node2节点更新数据

在mgr-node3节点更新数据

mgr多主模式下, 所有节点都可以进行读写操作.

2、切回单主模式

2.1、停止组复制(在所有mgr节点上执行):

stop group_replication;
set global group_replication_enforce_update_everywhere_checks=off;
set global group_replication_single_primary_mode=on;

2.2、选择一个节点作为主节点,在主节点上执行(186):

set global group_replication_bootstrap_group=on;
start group_replication;
set global group_replication_bootstrap_group=off;

2.3、在剩余节点,也就是从库节点上执行(194 195):

start group_replication;

2.4、查看mgr组信息(任意mgr节点上都可查看):

select * from performance_schema.replication_group_members;

切回单主模式,主具有读写权限,另外两个从节点只读不可写.

设置mgr组集群的白名单网段: 添加节点所在网段

stop group_replication;
set global group_replication_ip_whitelist="127.0.0.1/32,172.16.60.0/24,172.16.50.0/24,172.16.51.0/24";
start group_replication;
show variables like "group_replication_ip_whitelist";

知识点扩充

mysql group replication(mgr)是mysql官方在5.7.17版本引进的一个数据库高可用与高扩展的解决方案,以插件形式提供,实现了分布式下数据的最终一致性,总结mgr特点如下:

  • 高一致性:基于分布式paxos协议实现组复制,保证数据一致性;
  • 高容错性:自动检测机制,只要不是大多数节点都宕机就可以继续工作,内置防脑裂保护机制;
  • 高扩展性:节点的增加与移除会自动更新组成员信息,新节点加入后,自动从其他节点同步增量数据,直到与其他节点数据一致;
  • 高灵活性:提供单主模式和多主模式,单主模式在主库宕机后能够自动选主,所有写入都在主节点进行,多主模式支持多节点写入。

以上就是mysql mgr 单主多主模式切换知识点详解的详细内容,更多关于mysql mgr 单主多主模式切换的资料请关注移动技术网其它相关文章!

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网