mysql 主从数据同步
1.在主服务器中添加对应的用户和授权
CREATE USER 'test'@'%' IDENTIFIED BY 'test';
grant all privileges on *.* to test@'%' identified by 'test' with grant option;
2.在主服务器中mysql 安装文件中的my.ini 中添加
#Master Config
server-id=1;
log-bin=mysql-bin;
binlog-do-db=iot
3.在从服务器中mysql安装文件中的my.ini中添加
#Slave Config
server-id=2
log-bin=mysql-bin
replicate-do-db=iot
4.重启mysql服务,查看主服务器配置:
show master status;
显示:
File Position
mysql-bin.000001 154
5.在从服务器中输入命令
change master to master_host='192.168.0.22', master_user='test', master_password='test', master_log_file='mysql-bin.000001',master_log_pos=154;
6.重启从服务器mysql服务,查看从服务器配置:
show slave status;
7.使用start slave,及stop slave 进行操作