Windows下 mysql-8.x-winx64 集群-主从配置

主:192.168.1.20

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

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

重启服务

1
2
net stop mysql
net start mysql

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

1
2
3
4
CREATE USER 'slave'@'%' IDENTIFIED BY 'appblog.cn';
GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'slave'@'%';
-- GRANT ALL PRIVILEGES ON *.* TO 'slave'@'%';
flush privileges;

查看主节点状态

1
show master status;

从:192.168.1.21

my.ini 配置中新增配置

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

重启 mysql 服务

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

1
change master to master_host='192.168.1.20', master_user='slave', master_password='appblog.cn', master_port=3306, master_log_file='mysql-bin.000001', master_log_pos=0, master_connect_retry=30;

开启 slave

1
start slave;

查看从节点状态

1
show slave status;

若看到:

1
2
3
4
5
6
Slave_IO_State: Waiting for master
Master_Host: 192.168.1.20
...
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB: appblog

则说明从库已从主库,同步出 appblog 数据库,库中的表及表中内容已自动同步完成

Powered by AppBlog.CN     浙ICP备14037229号

Copyright © 2012 - 2021 APP开发技术博客 All Rights Reserved.

访客数 : | 访问量 :