Server version: 8.0.18-commercial MySQL Enterprise Server
MySQL在8.0.13后支持在线切换single primary和multi primary两种模式
切换至单主模式
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.02 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 | 93801cf6-2dcf-11ea-9190-fa163ee804c9 | dbmspredb308 | 3306 | ONLINE | PRIMARY | 8.0.18 |
| group_replication_applier | e277e47a-e9a6-11e9-ae34-fa163e137c0e | dbmspredb302 | 3306 | ONLINE | SECONDARY | 8.0.18 |
| group_replication_applier | e4ea91a6-e9a6-11e9-b7c0-fa163eb4f8e8 | dbmspredb304 | 3306 | ONLINE | SECONDARY | 8.0.18 |
+---------------------------+--------------------------------------+--------------+-------------+--------------+-------------+----------------+
3 rows in set (0.00 sec)
切换至多主模式
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 (1.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 | 93801cf6-2dcf-11ea-9190-fa163ee804c9 | dbmspredb308 | 3306 | ONLINE | PRIMARY | 8.0.18 |
| group_replication_applier | e277e47a-e9a6-11e9-ae34-fa163e137c0e | dbmspredb302 | 3306 | ONLINE | PRIMARY | 8.0.18 |
| group_replication_applier | e4ea91a6-e9a6-11e9-b7c0-fa163eb4f8e8 | dbmspredb304 | 3306 | ONLINE | PRIMARY | 8.0.18 |
+---------------------------+--------------------------------------+--------------+-------------+--------------+-------------+----------------+
3 rows in set (0.00 sec)