当主从库不同步的解决办法
本方法适用于主从数据库相差较大,或者要求数据完全统一的情况
1.先进入主库,进行锁表,防止数据写入。
使用命令:flush tables with read lock;(为只读状态,不区分大小写)
2.进行数据备份
进入dos,执行命令mysqldump -uroot -p -h127.0.0.1 test> D:\xx\test.bak.sql
3.将备份文件上传到从库机器,进行数据恢复
4.停止从库同步状态
stop slave;
5.进入从库,执行命令
use test;
source D:/xx/test.bak.sql; (此处为反斜杠)
6.查询主库状态
show master status;
7.设置主从同步
change master to master_host='127.0.0.1',master_port=3306,master_user='test',master_password='test123',master_log_file='mysql-log-bin.000001',master_log_pos=120;
8.开启同步
start slave;
9.查询从库状态
mysql> show slave status\G;
10.主库解锁
unlock tables;
转载请注明原文地址: https://ju.6miu.com/read-1125131.html