mysql 副本集_新特性解读 | MySQL 8.0 新特性-副本集(replicaset)

作者:杨涛涛

引言

MySQL Innodb Cluster = MySQL Shell + MySQL Router + MySQL Group Replication(MGR)

全程由 MySQL Shell 来管理操作 MGR 的聚合套件。MySQL 8.0.19 发布后,这种组合延伸到 MySQL Replication(主从复制),也就是 MySQL Shell + MySQL Router + MySQL Replication。

MySQL 主从复制,相信大家已经非常了解了,原理大概如下图:

c02d38d557233f1a4e2683696fa23958.png

一、环境准备

举个例子,搭建主从的基本步骤大概如下:

主机 A:192.168.2.171:4010

从机 B/C:192.168.2.171:4011 / 192.168.2.171:4012

主机和从机经过简单的配置,后期其他配置自己任意搭配(不同的主机要将 server-id 分别改成不同的就行了)

# my.cnf

server-id = 4010

log-bin=ytt

enforce_gtid_consistency=on

gtid_mode=on

log_slave_updates=on

master-info-repository=table

relay-log-info-repository=table

slave_parallel_type=logical

slave_parallel_workers=4

重启所有实例

systemctl restart mysql@{4010,4011,4012}

然后在 A 上创建主从需要的用户,并且分别在 B 和 C 上执行 change master to 命令配置从机即可。

我上面只是涉及到主从从零开始的场景,如果说主机 A 有数据,还得重加步骤。关于这点资料很多,我这里也就不多介绍了。那么对主从的管理没有搭建这么简单,稍微要繁琐些,譬如要实现如下的功能点:

主从级别互换:主机降级为从机;从机升级为主机。

从机由于异常,无法恢复正常;或者恢复正常了,发现数据和主机有差异,必须要重做从机,恢复主从关系。

列出主从关系,可能要自己写个小脚本或者是利用 MySQL Utility 工具集或者是其他的工具集合。

那接下来来看看 MySQL 8.0.19 中 MySQL Shell 新特性:副本集以及管理。

二、副本集

副本集也就是极度简化了对 MySQL 主从的相关管理操作。

那接下来还是用刚才那三个实例举例说明 MySQL Shell 怎么简化了相关操作。

进入 MySQL X 端口 40100

root@ytt-pc:/home/ytt/scripts# mysqlsh mysqlx://ytt@ytt-pc:40100

MySQL Shell 8.0.19

Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its affiliates.

Other names may be trademarks of their respective owners.

Type '\help' or '\?' for help; '\quit' to exit.

Creating an X protocol session to 'ytt@ytt-pc:40100'

Fetching schema names for autocompletion... Press ^C to stop.

Your MySQL connection id is 12 (X protocol)

Server version: 8.0.19 MySQL Community Server - GPL

No default schema selected; type \use to set one.

2.1 创建副本集 ytt_replicaset

MySQL ytt-pc:40100+ ssl JS > var c1 = dba.createReplicaSet("ytt_replicaset")

A new replicaset with instance 'ytt-pc:4010' will be created.

* Checking MySQL instance at ytt-pc:4010

This instance reports its own address as ytt-pc:4010

ytt-pc:4010: Instance configuration is suitable.

* Updating metadata...

ReplicaSet object successfully created for ytt-pc:4010.

Use rs.addInstance() to add more asynchronously replicated instances to this replicaset and rs.status() to ch

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值