master配置
1. 编译mysql配置文件,开启bin-log日志,并重启mysqld让配置文件生效
vim /etc/my.cnf
server-id=133 #最好是IP的最后一位数
log_bin=/var/log/mysql/mysql-bin.log
配置好后,重启mysql
systemctl restart mysqld
2.创建同步数据用户
grant replication slave on *.* to 'slave'@'%' identified by '123456';
flush privileges;
3.锁住主库表
flush tables with read lock;
4.查看主库状态
show master status
5.解锁数据库
unlock tables;
Slave配置
vim /etc/my.cnf
server-id=135 #最好是IP的最后一位数
log_bin=/var/log/mysql/mysql-bin.log
配置好后,重启mysql
systemctl restart mysqld
从库设置slave复制主库数据
change master to master_host='主mysql服务器ip',master_user='slave',master_password='123456',master_log_file='mysql-bin.000001',master_log_pos=19416434;
- show slave status;