采用组复制部署InnoDB集群
如果您有一个现有的组复制部署,并且希望使用它来创建一个集群,请将adoptFromGR选项传递给dba.createCluster()函数。创建的InnoDB集 群匹配复制组是单主还是多主。这意味着不能将multiPrimary选项与adoptFromGR选项结合使用。
组复制成员可能包含MyISAM表。将所有这样的表转换为InnoDB,然后再将组纳入InnoDB集群。
我这里已经存在组复制了
mysql> SELECT * FROM performance_schema.replication_group_members; +---------------------------+--------------------------------------+-------------+-------------+--------------+ | CHANNEL_NAME | MEMBER_ID | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE | +---------------------------+--------------------------------------+-------------+-------------+--------------+ | group_replication_applier | 07542900-d3b4-11ef-a088-005056a390e6 | mysqlcs | 3308 | ONLINE | | group_replication_applier | f81625c0-d3b3-11ef-9c8d-005056a390e6 | mysqlcs | 3306 | ONLINE | | group_replication_applier | ffc6ff15-d3b3-11ef-9e2d-005056a390e6 | mysqlcs | 3307 | ONLINE | +---------------------------+--------------------------------------+-------------+-------------+--------------+ 3 rows in set (0.01 sec)
要采用已有的组复制组,请使用MySQL Shell连接到组成员。使用dba.createCluster()创建一个集群,传入adoptFromGR选项。例如:
[root@mysqlcs ~]# mysqlsh --log-level=DEBUG3 root@localhost Please provide the password for 'root@localhost': ****** Save password for 'root@localhost'? [Y]es/[N]o/Ne[v]er (default No): MySQL Shell 8.0.41 Copyright (c) 2016, 2025, Oracle and/or its affiliates. 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 a session to 'root@localhost' Fetching schema names for auto-completion... Press ^C to stop. Your MySQL connection id is 94 (X protocol) Server version: 5.7.26-log Source distribution No default schema selected; type \useto set one. MySQL localhost:33060+ JS > var cluster = dba.createCluster('prodCluster', {adoptFromGR: true}) WARNING: Support for AdminAPI operations in MySQL version 5.7 is deprecated and will be removed in a future release of MySQL Shell A new InnoDB Cluster will be created based on the existing replication group on instance 'mysqlcs:3306'. Creating InnoDB Cluster 'prodCluster' on 'mysqlcs:3306'... Adding Seed Instance... Adding Instance 'mysqlcs:3308'... Adding Instance 'mysqlcs:3306'... Adding Instance 'mysqlcs:3307'... Resetting distributed recovery credentials across the cluster... WARNING: Instance 'mysqlcs:3308' cannot persist configuration since MySQL version 5.7.26 does not support the SET PERSIST command (MySQL version >= 8.0.11 required). Please use the dba.configureLocalInstance() command locally to persist the changes. WARNING: Instance 'mysqlcs:3306' cannot persist configuration since MySQL version 5.7.26 does not support the SET PERSIST command (MySQL version >= 8.0.11 required). Please use the dba.configureLocalInstance() command locally to persist the changes. WARNING: Instance 'mysqlcs:3307' cannot persist configuration since MySQL version 5.7.26 does not support the SET PERSIST command (MySQL version >= 8.0.11 required). Please use the dba.configureLocalInstance() command locally to persist the changes. Cluster successfully created based on existing replication group.
连接并对其发出dba.createCluster()的组复制成员用作创建组的种子实例。
MySQL localhost:33060+ JS > cluster.status() WARNING: Support for AdminAPI operations in MySQL version 5.7 is deprecated and will be removed in a future release of MySQL Shell { "clusterName": "prodCluster", "defaultReplicaSet": { "name": "default", "primary": "mysqlcs:3306", "ssl": "DISABLED", "status": "OK", "statusText": "Cluster is ONLINE and can tolerate up to ONE failure.", "topology": { "mysqlcs:3306": { "address": "mysqlcs:3306", "memberRole": "PRIMARY", "mode": "R/W", "readReplicas": {}, "role": "HA", "status": "ONLINE", "version": "5.7.26" }, "mysqlcs:3307": { "address": "mysqlcs:3307", "memberRole": "SECONDARY", "mode": "R/O", "readReplicas": {}, "role": "HA", "status": "ONLINE", "version": "5.7.26" }, "mysqlcs:3308": { "address": "mysqlcs:3308", "memberRole": "SECONDARY", "mode": "R/O", "readReplicas": {}, "role": "HA", "status": "ONLINE", "version": "5.7.26" } }, "topologyMode": "Single-Primary" }, "groupInformationSourceMember": "mysqlcs:3306" } MySQL localhost:33060+ JS > MySQL localhost:33060+ JS > cluster.describe(); WARNING: Support for AdminAPI operations in MySQL version 5.7 is deprecated and will be removed in a future release of MySQL Shell { "clusterName": "prodCluster", "defaultReplicaSet": { "name": "default", "topology": [ { "address": "mysqlcs:3308", "label": "mysqlcs:3308", "role": "HA" }, { "address": "mysqlcs:3306", "label": "mysqlcs:3306", "role": "HA" }, { "address": "mysqlcs:3307", "label": "mysqlcs:3307", "role": "HA" } ], "topologyMode": "Single-Primary" } } MySQL localhost:33060+ JS >