Windows下Mysql主从复制配置

首先在windows下装lian两个mysql   见文章

Windows安装两个mysql-->    https://blog.csdn.net/bestxianfeng163/article/details/85758820

1.主库my.ini配置

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.

[mysqld]

# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M

# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.

#服务id
server-id=1
#开启bin  Log日志
log-bin=mysql-bin

# These are commonly set, remove the # and set as required.
#同步的数据库
binlog-do-db=sharding_0
binlog-do-db=sharding_1
#binlog-ignore-db=mysql不需要同步的数据库
basedir = E:/mysql57
datadir =E:/mysql57/data
port = 3306
character-set-server=utf8

#socket = .....

# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M 

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 


2.启动主库服务

         net start mysql

         SHOW VARIABLES LIKE 'server_id';

          Windows下Mysql主从复制配置_第1张图片

        show master status;(这两个参数很重要,mysql-bin.000001和position 4679 通过这两个参数进行在从库中进行通讯)

                 (作用就是拿到主库数据库执行语句的程序执行id和执行语句)

Windows下Mysql主从复制配置_第2张图片 

3.在主库创建连接账号

//创建主从复制连接用户
GRANT REPLICATION SLAVE ON *.* TO 'slave'@'%' IDENTIFIED BY '123456';
//给用户分 分 配权限  *.* 所有数据库的所有表
GRANT ALL ON *.* TO 'slave'@'%';
flush privileges;

4.从库my.ini配置

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.

[mysqld]

# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M

# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
server-id=2
basedir = E:/mysql572
datadir =E:/mysql572/data
port = 3307
character-set-server=utf8
log-bin=mysql-bin
relay_log=mysql-relay-bin
# These are commonly set, remove the # and set as required.



#socket = .....

# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M 

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 


5.进行主从复制连接配置

change master to master_host='127.0.0.1',master_port=3306,
         master_user='slave',master_password='123456',
        master_log_file='mysql-bin.000001',master_log_pos=3808;
    master_log_file bin日志  在第二步对主库对应  master_log_pos 在第二步与主库对应

6.开启从库主从复制服务

start slave;//开启服务

show  slave status;//查看zhua状态

你可能感兴趣的:(Mysql)