MySQL 组复制
文章目录
环境
hostname | ip | os | mysql |
---|---|---|---|
mysql_11 | 192.168.1.11 | centos7.7 | 8.0.19 |
mysql_22 | 192.168.1.22 | centos7.7 | 8.0.19 |
mysql_33 | 192.168.1.33 | centos7.7 | 8.0.19 |
安装 mysql
- 懒得写了 …
修改 my.cnf
|
|
初始化集群
-
重新启动节点 mysql_11
1
systemctl restart mysqld
-
创建同步用户
1 2 3 4 5 6
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;
-
配置同步信息
1 2 3 4
CHANGE MASTER TO MASTER_USER='rpl_user', MASTER_PASSWORD='password' FOR CHANNEL 'group_replication_recovery';
-
启动集群
1 2 3
SET GLOBAL group_replication_bootstrap_group=ON; START GROUP_REPLICATION; SET GLOBAL group_replication_bootstrap_group=OFF;
-
查看集群成员(只有一个)
1
SELECT * FROM performance_schema.replication_group_members;
-
修改 my.cnf,配置 group-replication-start-on-boot = ON
增加节点
-
重新启动节点 mysql_22
1
systemctl restart mysql_22
-
创建同步用户,与 mysql_11 相同
1 2 3 4 5 6
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;
-
配置同步信息
1 2 3 4
CHANGE MASTER TO MASTER_USER='rpl_user', MASTER_PASSWORD='password' FOR CHANNEL 'group_replication_recovery';
-
启动组复制
1
START GROUP_REPLICATION;
-
在 mysql_33 上重复 mysql_22 的步骤
-
查看集群成员(有三个)
1
SELECT * FROM performance_schema.replication_group_members;
-
修改 mysql_22 和 mysql_33 的 my.cnf,配置 group-replication-start-on-boot = ON
注意
- 每张表都必须显式指定主键
文章作者 Colben
上次更新 2020-04-28