-- 创建一个MySQL InnoDB Cluster (MGR) 示例
-- 1. 创建一个具有复制权限的用户
CREATE USER 'replica_user'@'%' IDENTIFIED BY 'password';
GRANT REPLICATION SLAVE ON *.* TO 'replica_user'@'%';
-- 2. 配置第一个实例(假设端口为3306)
ALTER INSTANCE FOR GROUP_REPLICATION PRIMARY MEMBER SET ('group_replication_local_address':= 'server1:33061');
INSTALL PLUGIN group_replication SONAME 'group_replication.so';
SET GLOBAL group_replication_start_on_boot=OFF;
SET GLOBAL group_replication_bootstrap_group=ON;
START GROUP_REPLICATION;
SET GLOBAL group_replication_bootstrap_group=OFF;
-- 3. 配置第二个实例(假设端口为3307)
ALTER INSTANCE FOR GROUP_REPLICATION PRIMARY MEMBER SET ('group_replication_local_address':= 'server2:33061');
INSTALL PLUGIN group_replication SONAME 'group_replication.so';
SET GLOBAL group_replication_start_on_boot=OFF;
CHANGE MASTER TO MASTER_USER='replica_user', MASTER_PASSWORD='password' FOR CHANNEL 'group_replication_recovery';
START GROUP_REPLICATION;
-- 4. 配置第三个实例(假设端口为3308)
ALTER INSTANCE FOR GROUP_REPLICATION PRIMARY MEMBER SET ('group_replication_local_address':= 'server3:33061');
INSTALL PLUGIN group_replication SONAME 'group_replication.so';
SET GLOBAL group_replication_start_on_boot=OFF;
CHANGE MASTER TO MASTER_USER='replica_user', MASTER_PASSWORD='password' FOR CHANNEL 'group_replication_recovery';
START GROUP_REPLICATION;
-- 5. 检查集群状态
SELECT * FROM performance_schema.replication_group_members;
performance_schema.replication_group_members
表来检查集群成员的状态。以上代码展示了如何创建和配置一个基本的 MySQL InnoDB Cluster (MGR)。
上一篇:mysql增加字段
下一篇:ubuntu安装mysql5.7
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站