MYSQL主从库不同步故障一例解决方法


于是:

1、在主库中创建一个临时库,将需要导入的表文件复制过来

2、执行

create database tmpdb;

create table tmptable;

cp mysql_date_file master_data_file //shell command 复制数据表文件到master data_dir下

insert into master.tmptable select * from tmpdb.tmptable;

执行完后,主库中数据导入正常

再看slave status

show slave status;

发现错误:not found tmpdb.tmptable (大致意思是这个,原来的错误信息没有记录下来)

匆忙中,看show master status 中Master_Log_Pos 标记为$Master_Log_Pos

然后在slave 上 CHANGE MASTER TO MASTER_LOG_POS=$Master_Log_Pos

然后再看show master status,发现有1162错误

到现在发现两边的数据不能同步了

。。。。。。

冥思苦想,不会重新做一遍主从库吧?

mysqlbinlog 我突然想到了它

于是mysqlbinlog --start-position=190000000 --stop-position=200000000 xxx.binlog|grep tmptable

找到了在slave上执行错误的SQL

mysqlbinlog --start-position=190000000 --stop-position=200000000 xxx.binlog|grep tmptable > /tmp/tmpbinlog

vi /tmp/tmpbinlog (find tmptable)

找到错误SQL的下一个# at (一串数字)标记为$NEXT_POS

在slave 上 CHANGE MASTER TO MASTER_LOG_POS=$NEXT_POS

show slave status 显示:

Slave_IO_Running: Yes
Slave_SQL_Running: Yes

哈哈,完成同步。

如果中间碰到1062错误 在slave配置文件中设定slave-skip-errors=1062,重启slave
« 
» 
快速导航

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3