Last_SQL_Error: Could not execute Delete_rows event on table hcy.t1
Can't find record in 't1',
Error_code: 1032handler error HA_ERR_KEY_NOT_FOUND
the event's master log mysql-bin.000006, end_log_pos 254
第二种:主键重复。在slave已经有该记录,又在master上插入了同一条记录。
Last_SQL_Error: Could not execute Write_rows event on table hcy.t1
Duplicate entry '2' for key 'PRIMARY',
Error_code: 1062
handler error HA_ERR_FOUND_DUPP_KEYthe event's master log mysql-bin.000006, end_log_pos 924
第三种:在master上更新一条记录,而slave上找不到,丢失了数据。
Last_SQL_Error: Could not execute Update_rows event on table hcy.t1
Can't find record in 't1',
Error_code: 1032
handler error HA_ERR_KEY_NOT_FOUNDthe event's master log mysql-bin.000010, end_log_pos 263
异步半同步区别
mysql主从同步常见异常及恢复方法
1. 一般的异常只需要跳过一步即可恢复
>slave stop
>SET GLOBAL sql_slave_skip_counter = 1
>slave start
2.断电导致主从不能同步时,通主库的最后一个bin-log日志进行恢复
在主库服务器上,mysqlbinlog mysql-bin.xxxx >binxxxx.txt
tail -n 100000 binxxxx.txt >tail-binxxxx.txt
vim tail-binxxxx.txt 打开tail-binxxxx.txt文件找到最后一个postion值
然后在从库上,change host to 相应正确的值
>slave stop
>change master to master_host='ip', master_user='username', master_password='password', master_log_file='mysql-bin.xxxx', master_log_pos=xxxx
>slave start
>show slave status\G
3.主键冲突、表已存在等错误代码如1062,1032,1060等,可以在mysql主配置文件指定
略过此类异常并继续下条sql同步,这样也可以避免很多主从同步的异常中断
[mysqld]
slave-skip-errors = 1062,1032,1060
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)