master ip:10.30.xx.123;
slave ip : 10.30.xx.456
注意:如果主库有数据,需要先保证主从数据先一致,之后再开启slave机;
查看binlog是否开启
show variables like '%log_bin%'
开启binlog,主从都需要开启,配置完均要重启;
1.1、master的配置文件;
1.2、slave的配置文件
1.3、查看binlog日志
show master status;
reset master -- 生产环境慎用
2.1、在主库上创建用于同步的账号;
GRANT REPLICATION SLAVE ON *.* to 'mysyxs'@'%' identified by 'xxxx';
flush privileges;-- 刷新权限
3.1、为slave机器设置master的binlog文件以及位置 信息
change master to master_host='10.30.38.203',master_port=3306,master_user='mysyxs',master_password='whitebox123!',master_log_file='mysql-bin.000001',master_log_pos=154;
3.2 开启slave
start slave; -- 开启slave
show slave status\G; -- 查看状态
stop slave;
1、执行完 start slave 报错
ERROR 1200 (HY000): The server is not configured as slave; fix in config file or with CHANGE MASTER TO
原因:slave配置有问题,检查配置;
ERROR 1872 (HY000): Slave failed to initialize relay log info structure from the repository
原因:
可能是relay log 有历史记录,执行reset slave; 即可
reset slave;