Mysql主从库同步错误:1062 Error 'Duplicate entry '1438019'

mysql主从库同步错误:1062 Error ‘Duplicate entry ‘1438019‘ for key ‘PRIMARY‘‘ on query

mysql主从库在同步时会发生1062 Last_SQL_Error: Error ‘Duplicate entry ‘的问题:

显然这个问题是因为插入重复主键导致从库不工作了,错误消息如下

mysql> show slave status\G;

*************************** 1. row ***************************

Slave_IO_State: Waiting for master to send event

Master_Host: 192.168.10.100

Master_User: slave_user

Master_Port: 3306

Connect_Retry: 60

Master_Log_File: mysql-bin.000773

Read_Master_Log_Pos: 63325

Relay_Log_File: server122-relay-bin.000002

Relay_Log_Pos: 165661

Relay_Master_Log_File: mysql-bin.000771

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 ‘1438019‘ for key ‘PRIMARY‘‘ on query. Default database: ‘otrs‘. Query: ‘INSERT INTO ticket (tn, title, create_time_unix, queue_id, ticket_lock_id, user_id, group_id, ticket_priority_id, ticket_state_id, ticket_answered, escalation_start_time, timeout, valid_id, create_time, create_by, change_time, change_by) VALUES (‘2012061310001851‘, ‘Your order ORD201205A000016 was bounced back‘, 1339585744, 44, 1, 43, 1, 3, 4, 0, 1339585744, 0, 1, current_timestamp, 43, current_timestamp, 43)‘

Skip_Counter: 0

Exec_Master_Log_Pos: 41969067

Relay_Log_Space: 625695

Until_Condition: None

Until_Log_File:

Until_Log_Pos: 0

Master_SSL_Allowed: No

Master_SSL_CA_File:

Master_SSL_CA_Path:

Master_SSL_Cert:

Master_SSL_Cipher:

Master_SSL_Key:

Seconds_Behind_Master: NULL

Master_SSL_Verify_Server_Cert: No

Last_IO_Errno: 0

Last_IO_Error:

Last_SQL_Errno: 1062

Last_SQL_Error: Error ‘Duplicate entry ‘1438019‘ for key ‘PRIMARY‘‘ on query. Default database: ‘otrs‘. Query: ‘INSERT INTO ticket (tn, title, create_time_unix, queue_id, ticket_lock_id, user_id, group_id, ticket_priority_id, ticket_state_id, ticket_answered, escalation_start_time, timeout, valid_id, create_time, create_by, change_time, change_by) VALUES (‘2012061310001851‘, ‘Your order ORD201205A000016 was bounced back‘, 1339585744, 44, 1, 43, 1, 3, 4, 0, 1339585744, 0, 1, current_timestamp, 43, current_timestamp, 43)‘

1 row in set (0.00 sec)

ERROR:

No query specified

解决的办法是在从库上执行:

mysql> slave stop;

mysql> set GLOBAL SQL_SLAVE_SKIP_COUNTER=1;

mysql> slave start;

上面的方法可以解决问题,还有一种解决问题的办法是通过修改mysql的配置文件,让从库的同步线程忽略这个错误,方法:

修改mysql配置文件 /etc/my.cnf 在

[mysqld]下加一行 slave_skip_errors = 1062 ,保存.重启mysql. mysql slave可以正常同步了.

Mysql主从库同步错误:1062 Error 'Duplicate entry '1438019'

时间: 2024-07-29 04:56:18

Mysql主从库同步错误:1062 Error 'Duplicate entry '1438019'的相关文章

ERROR 1130: Host '192.168.1.3' is not allowed to connect to this MySQL ERROR 1062 (23000): Duplicate entry '%-root' for key 'PRIMARY'

use mysql mysql> select host, user from user; 将相应用户数据表中的host字段改成'%': update user set host='%' where user='root'; ERROR 1062 (23000): Duplicate entry '%-root' for key 'PRIMARY' 不予理会 flush privileges; 重新远程连接OK ERROR 1130: Host '192.168.1.3' is not allo

ERROR 1062 (23000): Duplicate entry '0' for key 'PRIMARY'

OS: centos 6.3DB: 5.5.14 测试创建yoon测试表,没有主键,没有索引,基础数据内容如下: mysql> select * from yoon;+----+----------+------+| id | name | user |+----+----------+------+| 1 | \""##!aa | NULL || 2 | z2 | NULL || 3 | z3 | NULL || 4 | z4 | NULL || 5 | z5 | NULL |

ERROR 1062 (23000): Duplicate entry '1-1' for key 'PRIMARY'

这个错误是说,由于某个SQL操作造成了,表中主键重复. 例子: create table t(x int,y int,z int, primary key(x,y)); insert into t(x,y,z) values(1,1,0),(1,2,0),(1,3,0); --在这里还是好的,下面我们要用一条语句来造成错误-- update t set y=1;-- 看到了没有,这一条语句会造成,三行重复的数据,所以它就报错了哦. ERROR 1062 (23000): Duplicate en

ERROR 1062 (23000): Duplicate entry for key 'PRIMARY'

ALTER TABLE table1 ADD COLUMN column1 VARCHAR(400) DEFAULT NULL; ERROR 1062 (23000): Duplicate entry '82133627' for key 'PRIMARY' select * from table1 where <primary_key_field>='82133627'; Primary key - primary_key_field int(11) NOT NULL solution -

mysql主从连接报错ERROR 1201

做主从同步时的报错: mysql> change master to master_host='192.168.10.151',master_user='repl',master_password='zrer90',master_log_file='mysql2-bin.000004',master_log_pos=98; ERROR 1201 (HY000): Could not initialize master info structure; more error messages can

mysql 主从同步故障解决 &nbsp; Error &#39;Row size too large (&gt; 8126).

错误日志:  Error 'Row size too large (> 8126). Changing some columns to TEXT or BLOB   or using ROW_FORMAT=DYNAMIC or ROW_FORMAT=COMPRESSED may help. In current row   format, BLOB prefix of 768 bytes is stored inline.' on query. Default   database: 'XXXX

一种粗暴快速的解决mysql主从不同步错误的思路

mysql主从经常会出现主从数据不同步的问题,脏数据会造成主从同步中断, 出现大量ERROR,如1032,1062等错误.常规方法是逐条删除脏数据或者 重做库,由于数据量大操作麻烦,而且主库在线上运行不能有锁表操作, 各种不便特别费时间.笔者在生产环境遭遇了一次,情急之下用粗暴的方法 不到10分种解决问题.下面假设一种情况,主库正常,从库数据不一致, 解决思路步骤如下: 1 ,对故障定性,通过查看最近日志来找出蛛丝马迹.一般都用mysqlbinlog /var/lib/myql/mysqld-b

mysql 主从库配置

MySQL从库上有一个IO线程负责从主库取binlog到写到本地.另外有一个SQL线程负责执行这些本地日志,实现命令重放: 一.环境 主机: master操作系统:centos 5.3 IP:192.168.1.222 MySQL版本:5.0.77 从机: slave操作系统:centos 5.3 IP:192.168.1.220 MySQL版本:5.0.77 二.创建数据库 分别登录master机和slave机的mysql:mysql –u root –p 创建数据库:create datab

mysql 主从库同步

#主库修改my.ini [mysqld] server-id=2 log-bin=mysql-bin binlog-do-db=demo #从库修改my.ini [mysqld] server-id=3 replicate-do-db=demo --配置完成后重启主从库 #主库为从库添加用户 grant replication slave,reload,super on *.* to slave@14.23.88.110 identified by '123456'; show master s