mysql8 windows 主从_Windows环境下设置MySql主从数据库

一、主(master)库配置

找到mysql目录下的 my.ini ,修改以下设置

[mysqld]

log-bin=mysql-bin

log-bin-index=mysql-bin.index

server-id=1

sync_binlog=1

binlog_format=mixed

binlog-do-db=test

binlog-ignore-db=mysql

binlog-ignore-db=performance_schema

binlog-ignore-db=information_schema

配置完成后重启mysql服务

创建一个从(slave)库使用的账号

GRANT REPLICATION SLAVE ON *.*TO 'root'@'192.168.1.162' IDENTIFIED BY '123456';

账号 :root

密码:123456

从库IP:192.168.1.162

权限:REPLICATION SLAVE

查询参数

主库设置完成,执行 show master status;

+------------------+----------+--------------+---------------------------------------------+-------------------+

| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |

+------------------+----------+--------------+---------------------------------------------+-------------------+

| mysql-bin.000001 | 8641 | measure | mysql,performance_schema,information_schema | |

+------------------+----------+--------------+---------------------------------------------+-------------------+

1 row in set

其中 file 、position 后面从库的设置中会用到,

Binlog_Do_DB 意思是指定从库复制哪个数据库,

Binlog_Ignore_DB 意思是忽略哪个数据库,

具体需求设置。

二、从(slave)库配置

找到mysql目录下的 my.ini ,修改以下设置

server-id=2

log-bin=mysql-bin

relay-log-index=slave-relay-bin.index

relay-log=slave-relay-bin

sync_master_info=1

sync_relay_log=1

sync_relay_log_info=1

配置完成后重启mysql服务

设置从库连接主库

# Master 服务器Ip

change master to master_host='xxx.xxx.xxx.xxx',

# Master 服务器端口号

master_port=3306,

# Master 中给从库设置的用户名

master_user='root',

# Master 中给从库设置的用户名对应的密码

master_password='123456',

# Master服务器产生的日志,参数取自主库 file字段

master_log_file='mysql-bin.000001',

# 参数取自主库position字段

master_log_pos=8641;

开启从库

start slave;

show slave status;

成功后看其中的两个参数Slave_IO_Running 和 Slave_SQL_Running 状态都为Yes则设置成功

ef5467a9fad8

1541127221312.png

以上是windows环境下设置mysql数据库主从库的配置流程,后续补充上读写分离的配置。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值