1. 服务器信息mysql
1.1 Ubuntu 17.0.4 (Master服务器)sql
MySQL版本: 5.7.20数据库
主数据库:dslbcp服务器
IP: 192.168.12.130 3306测试
1.2 Windows 10 (Slave服务器)spa
MySQL版本: 5.7.173d
从数据库:dslbcp (必与主数据彻底一致)日志
IP: 10.0.10.6 3306server
2.配置过程blog
2.1 Master服务器配置
2.1.1 MySQL配置文件 /etc/mysql/my.cnf 中添加内容:
[mysqld] log-bin=mysql-bin #日志文件 server-id=1 #服务器惟一标识 binlog-do-db=dslbcp #须要主从复制的数据库
2.1.2 重启MySQL服务
2.1.3 查看Master配置结果
SHOW MASTER STATUS;运行结果以下图1
OK, 没毛病!!!
2.1.4 受权MySQL用户
GRANT REPLICATION SLAVE ON *.* TO 'root'@'%' IDENTIFIED BY '12345678' WITH GRANT OPTION;
2.2 Slave服务器配置
2.2.1 MySQL配置文件 C:\ProgramData\MySQL\MySQL Server 5.7\my.ini 中添加内容:
[mysqld] replicate-do-db=dslbcp log_bin=mysql-bin relay_log=mysql-relay-bin
【注意Windows的MySQL配置文件在C:\ProgramData\MySQL\MySQL Server 5.7\my.ini】
2.2.2 重启MySQL服务
2.2.3 执行SQL语句
change master to master_host='192.168.12.130', master_user='root', master_password='12345678', master_log_file='mysql-bin.000003',master_log_pos=154;
master_host:Master主机地址
master_user:Master主机赋权限的用户名
master_password:Master主机赋权限时设置的密码
master_log_file: Master服务器运行语句 show master status 以后的显示的File 如上图1
master_log_pos:Master服务器运行语句show master status以后的显示的Position 如上图1
2.2.4 查看Slave配置结果
SHOW SLAVE STATUS; 运行结果以下图2的部分截图
关键是一下两列必须为YES, 以下图2的部分截图
3.测试主从
3.1.1 Master服务器上的MySQL对主数据库中的任意表执行 任意的查删改语句,Slave中的从数据库会保持与主数据库一致!!!以下图3: