mysql-8.0.21-winx64 集群-主从配置

2020-09-15  

主:172.31.32.184

1、主节点在 my.ini 文件新增配置

 

server-id=1
log-bin=mysql-bin

 

2、重启服务

net stop mysql
net start mysql

 

3、为从节点创建账号同步账号,授权

CREATE USER 'slave'@'%' IDENTIFIED BY 'constxiong@123';
GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'slave'@'%';
-- GRANT ALL PRIVILEGES ON *.* TO 'slave'@'%';
flush privileges; 

 

4、查看主节点状态

show master status;

 

从:172.31.32.234

5、my.ini 配置中新增配置

server-id=2
log-bin=mysql-slave-bin
relay_log=edu-mysql-relay-bin

 

6、重启 mysql 服务

 

7、配置从节点,从主同步数据

change master to master_host='172.31.32.184', master_user='slave', master_password='constxiong@123', master_port=3306, master_log_file='mysql-bin.000001', master_log_pos=0, master_connect_retry=30;

 

8、开启 slave

start slave;

 

9、查看从节点状态

show slave status;

从库已从主库,同步出 constxiong 数据库,库中的表及表中内容已自动同步完成。

ConstXiong 备案号:苏ICP备16009629号-3