Mysql configuration master-slave replication windows version

Mysql configuration master-slave replication windows version

master section

1 Create a new database

create database testdb character set=utf8;
use testdb;
create table t1(
	id int,
    name varchar(200)
);

2 Stop the database service

net stop mysql	

3 Edit the my.ini file and add the following configuration under [mysqld]

######主从复制 master 配置
server-id=1
#开启binlog 文件名(存放在mysql数据存放位置内)
log-bin=mysql-bin
#需要被复制的数据库名称
binlog-do-db=master
#不需要复制的数据库 二者不能同时出现
#binlog-ignore-db=xxx

Complete configuration file:

[mysqld]
# 设置3306端口
port=3307
# 设置mysql的安装目录
basedir=D:\mysql\mysql-5.7.25-winx64
# 设置mysql数据库的数据的存放目录
datadir=D:\mysql\mysql-5.7.25-winx64\mysql-5.7.25-winx64\data\
# 允许最大连接数
max_connections=200
# 允许连接失败的次数。
max_connect_errors=10
# 服务端使用的字符集默认为UTF8
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
# 默认使用“mysql_native_password”插件认证
#mysql_native_password
#default_authentication_plugin=mysql_native_password

######主从复制 master 配置
server-id=1
#开启binlog 文件名(存放在mysql数据存放位置内)
log-bin=mysql-bin
#需要被复制的数据库名称
binlog-do-db=master
#不需要复制的数据库 二者不能同时出现
#binlog-ignore-db=xxx

#######主从复制 slave 配置
#serve-id=2 slave只需要配置一个server-id 即可 注意server-id 必须保持唯一
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8
[client]
# 设置mysql客户端连接服务端时默认使用的端口
port=3307
default-character-set=utf8

4 Start the service

net start mysql

5 configuration

1. Create a user with a user name of slave and a user with a password of root that only has permission to copy

 grant replication slave on *.* to slave@'%'  identified by "123";

2 View the current status of the master

show master status;

Insert picture description here
Note that file and position need to be remembered

Slave node

1 Keep the database consistent with the master

create database testdb character set=utf8;
use testdb;
create table t1(
	id int,
    name varchar(200)
);

2 Stop the database service

net stop mysql

3 Edit the my.ini file and add the following configuration under [mysqld]

#从服务只需要配置一个server-id即可
server-id=2

4 Configure the slave service

-- 在mysql内 先停止 slave服务
stop slave;
-- 配置slave服务信息 注意 master_log_file 和 master_log_pos 和之前查看master的状态要保持一致
change master to 
master_host='127.0.0.1',
master_port=3307,
master_user='slave',
master_password='root',
master_log_file='mysql-bin.000002',
master_log_pos=444;
-- 启动 slave服务
start slave;
-- 查看 slave状态 看是否开启
-- Slave_IO_Running: Yes #负责与主机的io通信
-- Slave_SQL_Running: Yes #负责自己的slave mysql进程
show slave status;

test

Insert data on the main service and the slave service will automatically read the binlog log and back up the data

Guess you like

Origin blog.csdn.net/dndndnnffj/article/details/107286462