MGR(组复制)—单主模式与多主模式的切换

MySQL在8.0.13后支持在线切换single primary和multi primary两种模式,本文章讲解 MGR(组复制)的模式切换。

一、更改为单主模式

使用 group_replication_switch_to_single_primary_mode() UDF通过发出以下命令,将以多主要模式运行的组更改为单主要模式:

SELECT group_replication_switch_to_single_primary_mode();
mysql> SELECT group_replication_switch_to_single_primary_mode();
+---------------------------------------------------+
| group_replication_switch_to_single_primary_mode() |
+---------------------------------------------------+
| Mode switched to single-primary successfully.     |
+---------------------------------------------------+
1 row in set (0.01 sec)

mysql> SELECT * FROM performance_schema.replication_group_members;
+---------------------------+--------------------------------------+--------------+-------------+--------------+-------------+----------------+
| CHANNEL_NAME              | MEMBER_ID                            | MEMBER_HOST  | MEMBER_PORT | MEMBER_STATE | MEMBER_ROLE | MEMBER_VERSION |
+---------------------------+--------------------------------------+--------------+-------------+--------------+-------------+----------------+
| group_replication_applier | 47dfdfb5-32b5-11ea-a738-02000aba3d28 | 10.186.61.40 |        3306 | ONLINE       | PRIMARY     | 8.0.15         |
| group_replication_applier | 897b6353-32b9-11ea-a7e9-02000aba3d2e | 10.186.61.46 |        3306 | ONLINE       | SECONDARY   | 8.0.15         |
| group_replication_applier | a1796612-32b6-11ea-a32b-02000aba3d29 | 10.186.61.41 |        3306 | ONLINE       | SECONDARY   | 8.0.15         |
+---------------------------+--------------------------------------+--------------+-------------+--------------+-------------+----------------+

在操作运行期间,您可以通过发出以下命令来检查其进度:

SELECT event_name, work_completed, work_estimated FROM performance_schema.events_stages_current WHERE event_name LIKE "%stage/group_rpl%";
+----------------------------------------------------------------------------+----------------+----------------+
| event_name                                                                 | work_completed | work_estimated |
+----------------------------------------------------------------------------+----------------+----------------+
| stage/group_rpl/Primary Switch: waiting for pending transactions to finish |              4 |             20 |
+----------------------------------------------------------------------------+----------------+----------------+


二、更改为多主模式

使用 group_replication_switch_to_multi_primary_mode() UDF,通过发出以下命令,将以单主要模式运行的组更改为多主要模式:

SELECT group_replication_switch_to_multi_primary_mode();
mysql> SELECT group_replication_switch_to_multi_primary_mode();
+--------------------------------------------------+
| group_replication_switch_to_multi_primary_mode() |
+--------------------------------------------------+
| Mode switched to multi-primary successfully.     |
+--------------------------------------------------+
1 row in set (0.01 sec)

mysql> SELECT * FROM performance_schema.replication_group_members;
+---------------------------+--------------------------------------+--------------+-------------+--------------+-------------+----------------+
| CHANNEL_NAME              | MEMBER_ID                            | MEMBER_HOST  | MEMBER_PORT | MEMBER_STATE | MEMBER_ROLE | MEMBER_VERSION |
+---------------------------+--------------------------------------+--------------+-------------+--------------+-------------+----------------+
| group_replication_applier | 47dfdfb5-32b5-11ea-a738-02000aba3d28 | 10.186.61.40 |        3306 | ONLINE       | PRIMARY     | 8.0.15         |
| group_replication_applier | 897b6353-32b9-11ea-a7e9-02000aba3d2e | 10.186.61.46 |        3306 | ONLINE       | PRIMARY     | 8.0.15         |
| group_replication_applier | a1796612-32b6-11ea-a32b-02000aba3d29 | 10.186.61.41 |        3306 | ONLINE       | PRIMARY     | 8.0.15         |
+---------------------------+--------------------------------------+--------------+-------------+--------------+-------------+----------------+


经过一些协调的组操作以确保数据的安全性和一致性之后,属于该组的所有成员都将成为主成员。

当您将以单主要模式运行的组更改为以多主要模式运行时,如果运行的MySQL服务器版本高于最低版本的成员,则运行MySQL 8.0.17或更高版本的成员将自动置于只读模式。在组中。运行MySQL 8.0.16或更低版本的成员不执行此检查,并且始终处于读写模式。

在操作运行期间,您可以通过发出以下命令来检查其进度:

SELECT event_name, work_completed, work_estimated FROM performance_schema.events_stages_current WHERE event_name LIKE "%stage/group_rpl%";
+----------------------------------------------------------------------+----------------+----------------+
| event_name                                                           | work_completed | work_estimated |
+----------------------------------------------------------------------+----------------+----------------+
| stage/group_rpl/Multi-primary Switch: applying buffered transactions |              0 |              1 |
+----------------------------------------------------------------------+----------------+----------------+


 

你可能感兴趣的:(MySQL,数据库)