官方文档:In multi-primary mode, there is no notion of a single primary. There is no need to engage an election procedure since there is no server playing any special role.
在多主模式下,没有单主模式的概念。 没有必要使用选主程序,因为不同 server成员之间没有特殊的角色。
1、在gr1、gr2、gr3上停止组复制
[root@localhost][(none)]> stop group_replication;
Query OK, 0 rows affected (9.45 sec)
2、在gr1上开启Multi Primary组复制模式
[root@localhost][(none)]> set global group_replication_single_primary_mode=OFF;
Query OK, 0 rows affected (0.00 sec)
[root@localhost][(none)]> set global group_replication_enforce_update_everywhere_checks= ON;
Query OK, 0 rows affected (0.00 sec)
[root@localhost][(none)]> set global group_replication_bootstrap_group=ON;
Query OK, 0 rows affected (0.00 sec)
[root@localhost][(none)]> start group_replication;
Query OK, 0 rows affected (2.07 sec)
[root@localhost][(none)]> set global group_replication_bootstrap_group=OFF;
Query OK, 0 rows affected (0.00 sec)
3、在gr2和gr3上开启Multi Primary组复制模式
[root@localhost][(none)]> set global group_replication_single_primary_mode=OFF;
Query OK, 0 rows affected (0.00 sec)
[root@localhost][(none)]> set global group_replication_enforce_update_everywhere_checks= ON;
Query OK, 0 rows affected (0.00 sec)
[root@localhost][(none)]> START group_replication;
Query OK, 0 rows affected (3.12 sec)
4、查看Multi Primary模式的主节点
[root@localhost][(none)]> select * from performance_schema.replication_group_members;
+---------------------------+--------------------------------------+-------------+-------------+--------------+
| CHANNEL_NAME | MEMBER_ID | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE |
+---------------------------+--------------------------------------+-------------+-------------+--------------+
| group_replication_applier | 3ac20522-27d6-11e8-8b41-080027049941 | gr2 | 3306 | ONLINE |
| group_replication_applier | 56ba1eb1-27d6-11e8-8c74-08002750f3b8 | gr3 | 3306 | ONLINE |
| group_replication_applier | 783e5b4c-27d4-11e8-ba62-080027a663f9 | gr1 | 3306 | ONLINE |
+---------------------------+--------------------------------------+-------------+-------------+--------------+
3 rows in set (0.00 sec)
[root@localhost][(none)]> select * from performance_schema.global_status where VARIABLE_NAME='group_replication_primary_member';
+----------------------------------+----------------+
| VARIABLE_NAME | VARIABLE_VALUE |
+----------------------------------+----------------+
| group_replication_primary_member | |
+----------------------------------+----------------+
1 row in set (0.00 sec)
5、在gr1、gr2、gr3上插入数据
gr1:
[root@localhost][(none)]> select * from test.t1;
+----+
| id |
+----+
| 1 |
| 2 |
| 4 |
+----+
3 rows in set (0.00 sec)
[root@localhost][(none)]> insert into test.t1 values (3);
Query OK, 1 row affected (0.00 sec)
gr3:
[root@localhost][(none)]> insert into test.t1 values (5);
Query OK, 1 row affected (0.01 sec)
[root@localhost][(none)]> select * from test.t1;
+----+
| id |
+----+
| 1 |
| 2 |
| 3 |
| 4 |
| 5 |
+----+
5 rows in set (0.00 sec)
gr2:
[root@localhost][(none)]> insert into test.t1 values (6);
Query OK, 1 row affected (0.02 sec)
[root@localhost][(none)]> select * from test.t1;
+----+
| id |
+----+
| 1 |
| 2 |
| 3 |
| 4 |
| 5 |
| 6 |
+----+
6 rows in set (0.00 sec)