通过查看从服务器的状态,可以看到对应的错误信息
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.77.134
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: syntest.000001
Read_Master_Log_Pos: 13691
Relay_Log_File: centos0-relay-bin.000002
Relay_Log_Pos: 318
Relay_Master_Log_File: syntest.000001
Slave_IO_Running: Yes
Slave_SQL_Running: No
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 1062
Last_Error: Error 'Duplicate entry 'xxx' for key 'PRIMARY'' on query. Default database:...
...
1、 再次同步一次
mysql> stop slave;
Query OK, 0 rows affected, 1 warning (0.03 sec)
mysql> change master to master_host='192.168.77.134', master_user='repl', master_password='test111', master_log_file='syntest.000001', master_log_pos=13691;
Query OK, 0 rows affected, 2 warnings (0.20 sec)
mysql> start slave;
Query OK, 0 rows affected (0.24 sec)
2、跳过当前这个错误,在从库中执行
mysql> stop slave;
Query OK, 0 rows affected, 1 warning (0.03 sec)
mysql> set global sql_slave_skip_counter=1; -- 1 指跳过一个错误
Query OK, 0 rows affected (0.00 sec)
mysql> start slave;
Query OK, 0 rows affected (0.24 sec)
3、忽略该类型的错误,更改从库的配置,[mysqld]下加一行slave_skip_errors = 1062 ,保存重启mysql(/etc/init.d/mysqld restart)。