mysql> SET SQL_LOG_BIN=0; CREATE USER repl@'%' IDENTIFIED BY '12345678'; GRANT REPLICATION SLAVE ON *.* TO repl@'%'; FLUSH PRIVILEGES; SET SQL_LOG_BIN=1; CHANGE MASTER TO MASTER_USER='repl', MASTER_PASSWORD='12345678' FOR CHANNEL 'group_replication_recovery'; #安装组复制插件 INSTALL PLUGIN group_replication SONAME 'group_replication.so'; #查看插件是否安装成功 SHOW PLUGINS;
插件安装完成之后,将配置文件注释的那两行#去掉,重启数据库,并启动组复制进程:
1 2 3 4 5 6
#启动组复制 SET GLOBAL group_replication_bootstrap_group=ON; START GROUP_REPLICATION; SET GLOBAL group_replication_bootstrap_group=OFF; #查看组成员 SELECT * FROM performance_schema.replication_group_members;
mysql> CREATE DATABASE test1; USE test; CREATE TABLE t4 (c1 INT PRIMARY KEY, c2 TEXT NOT NULL); INSERT INTO t4 VALUES (1, 'Luis'); 检查表t1和二进制日志的内容。 SELECT * FROM t4; SHOW BINLOG EVENTS;
3、从节点2(dax-mysql-slave)执行:
1 2 3 4 5 6 7 8
SET SQL_LOG_BIN=0; CREATE USER repl@'%' IDENTIFIED BY '12345678'; GRANT REPLICATION SLAVE ON *.* TO repl@'%'; FLUSH PRIVILEGES; SET SQL_LOG_BIN=1; CHANGE MASTER TO MASTER_USER='repl', MASTER_PASSWORD='12345678' FOR CHANNEL 'group_replication_recovery'; INSTALL PLUGIN group_replication SONAME 'group_replication.so'; show plugins;
将配置文件注释的那两行#去掉,重启数据库
1
mysql>START GROUP_REPLICATION;
4、从节点3(dax-mysql-mha)执行:
1 2 3 4 5 6 7 8
SET SQL_LOG_BIN=0; CREATE USER repl@'%' IDENTIFIED BY '12345678'; GRANT REPLICATION SLAVE ON *.* TO repl@'%'; FLUSH PRIVILEGES; SET SQL_LOG_BIN=1; CHANGE MASTER TO MASTER_USER='repl', MASTER_PASSWORD='12345678' FOR CHANNEL 'group_replication_recovery'; INSTALL PLUGIN group_replication SONAME 'group_replication.so'; show plugins;
MySQL Shell用来配置服务器以供InnoDB集群使用的供应脚本需要访问Python版本2.7。对于沙箱部署,在用于部署的单台机器上需要Python,生产部署需要在每个服务器实例上使用Python。
1 2
tar -zxvf mysql-shell-8.0.11-linux-glibc2.12-x86-64bit.tar.gz mv mysql-shell-8.0.11-linux-glibc2.12-x86-64bit mysql-shell
主节点1(dax-mysql-master),连接主节点,授权repl用户集群管理权限
1 2 3 4
GRANT ALL PRIVILEGES ON mysql_innodb_cluster_metadata.* TO repl@'%' identified by '12345678' WITH GRANT OPTION; GRANT RELOAD, SHUTDOWN, PROCESS, FILE, SUPER, REPLICATION SLAVE, REPLICATION CLIENT, CREATE USER ON *.* TO repl@'%' identified by '12345678' WITH GRANT OPTION; GRANT SELECT ON *.* TO repl@'%' identified by '12345678' WITH GRANT OPTION; flush privileges;
SELECT * FROM performance_schema.replication_group_members;
查看主节点
1
SHOW STATUS LIKE 'group_replication_primary_member';
或者使用如下方法
1 2
set global show_compatibility_56 = on; select MEMBER_HOST from performance_schema.replication_group_members where MEMBER_ID=(select VARIABLE_VALUE from information_schema.global_status where variable_name='GROUP_REPLICATION_PRIMARY_MEMBER');