组复制安装部署 | 全方位认识 MySQL 8( 七 )


2)启动s3数据库进程,并使用客户端登录到数据库中,为组复制通道配置以及分布式恢复的用户凭证 。
SET SQL_LOG_BIN=0;CREATE USER rpl_user@'%' IDENTIFIED BY 'password';GRANT REPLICATION SLAVE ON *.* TO rpl_user@'%';GRANT BACKUP_ADMIN ON *.* TO rpl_user@'%';FLUSH PRIVILEGES;SET SQL_LOG_BIN=1;CHANGE MASTER TO MASTER_USER='rpl_user', MASTER_PASSWORD='password' FOR CHANNEL 'group_replication_recovery';
3)加载MGR插件并启动组复制
INSTALL PLUGIN group_replication SONAME 'group_replication.so';START GROUP_REPLICATION;
此时,名为s3的MySQL 已经启动并运行,且已经加入了组,并赶上了组中的其他成员中的数据 。通过查询.mbers表我们可以看到s3已经成功加入组且为状态,如下:
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 | ac39f1e6-6dfa-11e6-a69d-00212844f856 | s2 | 3306 | ONLINE | SECONDARY | 8.0.17 || group_replication_applier | 7eb217ff-6df3-11e6-966c-00212844f856 | s3 | 3306 | ONLINE | SECONDARY | 8.0.17 || group_replication_applier | 95409e1-6dfa-11e6-970b-00212844f856 | s1 | 3306 | ONLINE | PRIMARY | 8.0.17 |+---------------------------+--------------------------------------+-------------+-------------+--------------+-------------+----------------+3 rows in set (0.00 sec)
接下来,在s3中简单验证下数据是否同步完成,我们可以看到,在s3上的数据与在s1和s2中查询到的数据结果集相同 。
mysql> SHOW DATABASES LIKE 'test';+-----------------+| Database (test) |+-----------------+| test |+-----------------+mysql> SELECT * FROM test.t1;+----+------+| c1 | c2 |+----+------+| 1 | Luis |+----+------+mysql> SHOW BINLOG EVENTS;+---------------+------+----------------+-----------+-------------+--------------------------------------------------------------------+| Log_name | Pos | Event_type | Server_id | End_log_pos | Info |+---------------+------+----------------+-----------+-------------+--------------------------------------------------------------------+| binlog.000001 | 4 | Format_desc | 3 | 123 | Server ver: 8.0.19-log, Binlog ver: 4 || binlog.000001 | 123 | Previous_gtids | 3 | 150 | || binlog.000001 | 150 | Gtid | 1 | 211 | SET @@SESSION.GTID_NEXT= 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa:1' || binlog.000001 | 211 | Query | 1 | 270 | BEGIN || binlog.000001 | 270 | View_change | 1 | 369 | view_id=14724832985483517:1 || binlog.000001 | 369 | Query | 1 | 434 | COMMIT || binlog.000001 | 434 | Gtid | 1 | 495 | SET @@SESSION.GTID_NEXT= 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa:2' || binlog.000001 | 495 | Query | 1 | 585 | CREATE DATABASE test || binlog.000001 | 585 | Gtid | 1 | 646 | SET @@SESSION.GTID_NEXT= 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa:3' || binlog.000001 | 646 | Query | 1 | 770 | use `test`; CREATE TABLE t1 (c1 INT PRIMARY KEY, c2 TEXT NOT NULL) || binlog.000001 | 770 | Gtid | 1 | 831 | SET @@SESSION.GTID_NEXT= 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa:4' || binlog.000001 | 831 | Query | 1 | 890 | BEGIN || binlog.000001 | 890 | Table_map | 1 | 933 | table_id: 108 (test.t1) || binlog.000001 | 933 | Write_rows | 1 | 975 | table_id: 108 flags: STMT_END_F || binlog.000001 | 975 | Xid | 1 | 1002 | COMMIT /* xid=29 */ || binlog.000001 | 1002 | Gtid | 1 | 1063 | SET @@SESSION.GTID_NEXT= 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa:5' || binlog.000001 | 1063 | Query | 1 | 1122 | BEGIN || binlog.000001 | 1122 | View_change | 1 | 1261 | view_id=14724832985483517:2 || binlog.000001 | 1261 | Query | 1 | 1326 | COMMIT || binlog.000001 | 1326 | Gtid | 1 | 1387 | SET @@SESSION.GTID_NEXT= 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa:6' || binlog.000001 | 1387 | Query | 1 | 1446 | BEGIN || binlog.000001 | 1446 | View_change | 1 | 1585 | view_id=14724832985483517:3 || binlog.000001 | 1585 | Query | 1 | 1650 | COMMIT |+---------------+------+----------------+-----------+-------------+--------------------------------------------------------------------+