Master:192.168.100.1
Slave1:192.168.100.2
Slave2:192.168.100.3
mysql> install plugin group_replication soname 'group_replication.so';
mysql> set sql_log_bin=0;
Query OK, 0 rows affected (0.00 sec)
mysql> grant replication slave on *.* to rep@'%' identified by 'rep';
Query OK, 0 rows affected, 1 warning (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> set sql_log_bin=1;
Query OK, 0 rows affected (0.00 sec)
mysql> change master to
-> master_user='rep',
-> master_password='rep' for channel 'group_replication_recovery';
Query OK, 0 rows affected, 2 warnings (0.25 sec)
mysql> set global group_replication_bootstrap_group=on;
Query OK, 0 rows affected (0.00 sec)
mysql> start group_replication;
Query OK, 0 rows affected (2.12 sec)
mysql> install plugin group_replication soname 'group_replication.so';
Query OK, 0 rows affected (0.16 sec)
mysql> set sql_log_bin=0;
Query OK, 0 rows affected (0.00 sec)
mysql> grant replication slave on *.* to rep@'%' identified by 'rep';
Query OK, 0 rows affected, 1 warning (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> set sql_log_bin=1;
Query OK, 0 rows affected (0.00 sec)
mysql> change master to
-> master_user='rep',
-> master_password='rep' for channel 'group_replication_recovery';
Query OK, 0 rows affected, 2 warnings (0.02 sec)
mysql> start group_replication;
*注意* 若启动GR时报错ERROR 3092,执行:set global group_replication_allow_local_disjoint_gtids_join=ON;(感谢CSDN博主lijingkuan,这个解决方法是从他的博客上看到的)
node 1
mysql> select if((select @@server_uuid) = (select variable_value from performance_schema.global_status where variable_name = 'group_replication_primary_member'),1,0) as is_primary_mode ,@@server_id;
+-----------------+-------------+
| is_primary_mode | @@server_id |
+-----------------+-------------+
| 1 | 10013306 |
+-----------------+-------------+
1 row in set (0.00 sec)
node 2
mysql> select if((select @@server_uuid) = (select variable_value from performance_schema.global_status where variable_name = 'group_replication_primary_member'),1,0) as is_primary_mode ,@@server_id;
+-----------------+-------------+
| is_primary_mode | @@server_id |
+-----------------+-------------+
| 0 | 10023306 |
+-----------------+-------------+
1 row in set (0.00 sec)
node 3
mysql> select if((select @@server_uuid) = (select variable_value from performance_schema.global_status where variable_name = 'group_replication_primary_member'),1,0) as is_primary_mode ,@@server_id;
+-----------------+-------------+
| is_primary_mode | @@server_id |
+-----------------+-------------+
| 0 | 10033306 |
+-----------------+-------------+
1 row in set (0.00 sec)
node 1
mysql> select * from performance_schema.replication_group_members;
+---------------------------+--------------------------------------+--------------+-------------+--------------+
| CHANNEL_NAME | MEMBER_ID | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE |
+---------------------------+--------------------------------------+--------------+-------------+--------------+
| group_replication_applier | a18e7228-466b-11e9-86e7-000c290e71ea | mysql-master | 3306 | ONLINE |
+---------------------------+--------------------------------------+--------------+-------------+--------------+
1 row in set (0.00 sec)
mysql> select * from performance_schema.replication_group_member_stats\G
*************************** 1. row ***************************
CHANNEL_NAME: group_replication_applier
VIEW_ID: 15525782630353927:9
MEMBER_ID: a18e7228-466b-11e9-86e7-000c290e71ea
COUNT_TRANSACTIONS_IN_QUEUE: 0
COUNT_TRANSACTIONS_CHECKED: 0
COUNT_CONFLICTS_DETECTED: 0
COUNT_TRANSACTIONS_ROWS_VALIDATING: 0
TRANSACTIONS_COMMITTED_ALL_MEMBERS: 6953c9da-466c-11e9-8fee-000c2995023e:1-3,
a18e7228-466b-11e9-86e7-000c290e71ea:1-3,
a876d35e-9110-11e6-a365-842b2b5909d6:1-5
LAST_CONFLICT_FREE_TRANSACTION:
1 row in set (0.00 sec)
mysql> select * from performance_schema.replication_group_members where member_id=(select variable_value from performance_schema.global_status where variable_name='group_replication_primary_member');
+---------------------------+--------------------------------------+--------------+-------------+--------------+
| CHANNEL_NAME | MEMBER_ID | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE |
+---------------------------+--------------------------------------+--------------+-------------+--------------+
| group_replication_applier | a18e7228-466b-11e9-86e7-000c290e71ea | mysql-master | 3306 | ONLINE |
+---------------------------+--------------------------------------+--------------+-------------+--------------+
1 row in set (0.00 sec)