cat > cluster_auth_init.sql <<-eof
# 如下操作不记录二进制日志
SET SQL_LOG_BIN=0;
# 创建rpl_user账户,此账户用于实现主从数据同步
CREATE USER rpl_user@'%' IDENTIFIED BY '123456';
GRANT REPLICATION SLAVE ON *.* TO rpl_user@'%';
GRANT CONNECTION_ADMIN ON *.* TO rpl_user@'%';
GRANT BACKUP_ADMIN ON *.* TO rpl_user@'%';
GRANT GROUP_REPLICATION_STREAM ON *.* TO rpl_user@'%';
# 创建一个远程连接用户,便于图形化管理工具使用
create user 'remote'@'%' identified with mysql_native_password by '123456';
grant all privileges on *.* to remote@'%';
FLUSH PRIVILEGES;
# 恢复二进制日志功能并且重置二进制日志
SET SQL_LOG_BIN=1;
RESET MASTER;
eof
执行脚本
复制代码
mysql -uroot -p'123456' < cluster_auth_init.sql
15主机设定脚本
复制代码
cat > cluster_auth_init.sql <<-eof
SET SQL_LOG_BIN=0;
CREATE USER rpl_user@'%' IDENTIFIED BY '123456';
GRANT REPLICATION SLAVE ON *.* TO rpl_user@'%';
GRANT CONNECTION_ADMIN ON *.* TO rpl_user@'%';
GRANT BACKUP_ADMIN ON *.* TO rpl_user@'%';
GRANT GROUP_REPLICATION_STREAM ON *.* TO rpl_user@'%';
create user 'remote'@'%' identified with mysql_native_password by '123456';
grant all privileges on *.* to remote@'%';
FLUSH PRIVILEGES;
SET SQL_LOG_BIN=1;
RESET MASTER;
eof
执行脚本
复制代码
mysql -uroot -p'123456' < cluster_auth_init.sql
18主机设定脚本
复制代码
cat > cluster_auth_init.sql <<-eof
> SET SQL_LOG_BIN=0;
> CREATE USER rpl_user@'%' IDENTIFIED BY '123456';
> GRANT REPLICATION SLAVE ON *.* TO rpl_user@'%';
> GRANT CONNECTION_ADMIN ON *.* TO rpl_user@'%';
> GRANT BACKUP_ADMIN ON *.* TO rpl_user@'%';
> GRANT GROUP_REPLICATION_STREAM ON *.* TO rpl_user@'%';
> create user'remote'@'%' identified with mysql_native_password by '123456';
> grant all privileges on *.* to remote@'%';
> FLUSH PRIVILEGES;
> SET SQL_LOG_BIN=1;
> RESET MASTER;
> eof
执行脚本
复制代码
mysql -uroot -p'123456' < cluster_auth_init.sql
查看集群插件
12主机
复制代码
mysql -uroot -p'123456' -e "show plugins;"
15主机
复制代码
mysql -uroot -p'123456' -e "show plugins;"
18主机
复制代码
mysql -uroot -p'123456' -e "show plugins;"
启动集群环境
复制代码
SET GLOBAL group_replication_bootstrap_group=ON;
START GROUP_REPLICATION USER='rpl_user', PASSWORD='123456';
SET GLOBAL group_replication_bootstrap_group=OFF;