主键重复
场景说明:
在主从数据不一致情况下,slave已经有id为2数据,在master上没有id为2数据,往主库上写入id=2的数据。
主库t1数据:
mysql> select * from t1;
+----+------+
| id | name |
+----+------+
| 1 | 1 |
+----+------+
从库t1数据:
mysql> select * from t1;
+----+------+
| id | name |
+----+------+
| 1 | 1 |
| 2 | 2 |
+----+------+
从库中断原因:
Last_Error: Error 'Duplicate entry '2' for key 'PRIMARY'' on query. Default database: 'test'. Query: 'insert into t1(id,name)value(2,2)' |
解决方法:
stop slave;
delete from t1 where id=2;
start slave;
查看"show slave status\G",同步情况:
Slave_IO_Running: Yes
Slave_SQL_Running: Yes