这个算不算解决,我都不太清楚,因为我感觉网上的说法,只是把错误忽略了,不表示以后用从库时不会出问题!!!

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

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可以正常同步了.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

专业点的是以下这个:

线上环境我从来没有碰到过1062的问题,测试环境开发环境不停的出现类似问题,以往为了赶时间都是skip或者直接重新做,这会有时间,就好好去查查问题所在。

1 从库报错信息: 
mysql> show slave status\G 
*************************** 1. row *************************** 
               Slave_IO_State: Waiting for master to send event 
                  Master_Host: xxxx0402.china.online.ea.com 
                  Master_User: replication 
                  Master_Port: 3306 
                Connect_Retry: 60 
              Master_Log_File: mysql-bin.000154 
          Read_Master_Log_Pos: 56680675 
               Relay_Log_File: mysql-relay-bin.000455 
                Relay_Log_Pos: 33013454 
        Relay_Master_Log_File: mysql-bin.000152 
             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 '250.1.1-rding-changelogs/myIDENTITY/250/xxxx.xml' for key 'PRIMARY'' on query. Default database: 'identity'. Query: 'INSERT INTO `DATABASECHANGELOG` (`DATEEXECUTED`, `AUTHOR`, `xxxx`, `DESCRIPTION`, `COMMENTS`, `MD5SUM`, `ID`, `FILENAME`) VALUES (NOW(), 'rding', '1.9.3', 'Custom SQL', '', '4ac9fbf5222bc344362ccdecbc072', '250.1.1', 'changelogs/myIDENTITY/250/xxxx.xml')' 
                 Skip_Counter: 0 
          Exec_Master_Log_Pos: 33013308 
              Relay_Log_Space: 33020134 
              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 '250.1.1-rding-changelogs/myIDENTITY/250/xxxx.xml' for key 'PRIMARY'' on query. Default database: 'identity'. Query: 'INSERT INTO `DATABASECHANGELOG` (`DATEEXECUTED`, `AUTHOR`, `xxxx`, `DESCRIPTION`, `COMMENTS`, `MD5SUM`, `ID`, `FILENAME`) VALUES (NOW(), 'rding', '1.9.3', 'Custom SQL', '', '4ac9fbf5222bc344362ccdecbc072', '250.1.1', 'changelogs/myIDENTITY/250/xxxx.xml')' 
  Replicate_Ignore_Server_Ids:  
             Master_Server_Id: 1 
1 row in set (0.00 sec)

2 看表结构 
mysql> show create table DATABASECHANGELOG; 
+-------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 
| Table             | Create Table                                                                                                                                                                                                                                                                                                                                                                                                                                              | 
+-------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 
| DATABASECHANGELOG | CREATE TABLE `databasechangelog` ( 
  `ID` varchar(63) NOT NULL, 
  `AUTHOR` varchar(63) NOT NULL, 
  `FILENAME` varchar(200) NOT NULL, 
  `DATEEXECUTED` datetime NOT NULL, 
  `MD5SUM` varchar(32) DEFAULT NULL, 
  `DESCRIPTION` varchar(255) DEFAULT NULL, 
  `COMMENTS` varchar(255) DEFAULT NULL, 
  `TAG` varchar(255) DEFAULT NULL, 
  `xxxx` varchar(10) DEFAULT NULL, 
  PRIMARY KEY (`ID`,`AUTHOR`,`FILENAME`) 坑爹的表设计结构,不是我喜欢的风格 
) ENGINE=InnoDB DEFAULT CHARSET=utf8 | 
+-------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 
1 row in set (0.00 sec)

3 看已经存在的数据 
mysql> select * from DATABASECHANGELOG  where AUTHOR ='rding'; 
+---------+--------+-----------------------------------------+---------------------+----------------------------------+-------------+------------------------------------------+------+-----------+ 
| ID      | AUTHOR | FILENAME                                | DATEEXECUTED        | MD5SUM                           | DESCRIPTION | COMMENTS                                 | TAG  | xxxx |
+---------+--------+-----------------------------------------+---------------------+----------------------------------+-------------+------------------------------------------+------+-----------+ 
| 250.1.1 | rding  | changelogs/myIDENTITY/250/xxxx.xml | 2013-08-12 20:41:22 | 4ac9fbf5222bc344362ccdecbc072    | Custom SQL  |                                          | NULL | 1.9.3     | 
| 250.1.2 | rding  | changelogs/myIDENTITY/250/xxxx.xml | 2013-08-12 20:41:22 | 8463e1cf4ba029e3ace675d3e69a71d2 | Custom SQL  | Create new table for email change record | NULL | 1.9.3     | 
+---------+--------+-----------------------------------------+---------------------+----------------------------------+-------------+------------------------------------------+------+-----------+ 
2 rows in set (0.00 sec)

4 看binlog,在Relay_Master_Log_File: mysql-bin.000152,去主库找这个binlog解析出来 
解析 
[root@xxxx0402 tmp]# mysqlbinlog mysql-bin.000152 > a152.log 
搜索包含'rding'字符串的语句,因为这个是主键字段之一,所以检索起来应该比较容易。 
[root@xxxx0402 tmp]# grep a152.log 'rding' > rd.log 
grep: rding: No such file or directory 
[root@xxxx0402 tmp]# grep  'rding' a152.log > rd.log 
[root@xxxx0402 tmp]# ll

[root@xxxx0402 tmp]# more rd.log  
INSERT INTO `DATABASECHANGELOG` (`DATEEXECUTED`, `AUTHOR`, `xxxx`, `DESCRIPTION`, `COMMENTS`, `MD5SUM`, `ID`, `FILENAME`) VALUES (NOW(), 'rding', '1.9.3', 'Custom 
 SQL', '', '4ac9fbf5222bc344362ccdecbc072', '250.1.1', 'changelogs/myIDENTITY/250/xxxx.xml') 
INSERT INTO `DATABASECHANGELOG` (`DATEEXECUTED`, `AUTHOR`, `xxxx`, `DESCRIPTION`, `COMMENTS`, `MD5SUM`, `ID`, `FILENAME`) VALUES (NOW(), 'rding', '1.9.3', 'Custom 
 SQL', 'Create new table for email change record', '8463e1cf4ba029e3ace675d3e69a71d2', '250.1.2', 'changelogs/myIDENTITY/250/xxxx.xml')

主库上面只有一条insert sql语句。

5 再去看从库的relay log日志Relay_Log_File: mysql-relay-bin.000455 
[root@eanshlt2mydbc004db002 data]# cp mysql-relay-bin.000455 /tmp 
[root@eanshlt2mydbc004db002 data]# cd /tmp 
[root@eanshlt2mydbc004db002 tmp]# mysqlbinlog mysql-relay-bin.000455 > relay.log 
[root@eanshlt2mydbc004db002 tmp]#  
[root@eanshlt2mydbc004db002 tmp]# grep  'rding' relay.log > rd.log 
[root@eanshlt2mydbc004db002 tmp]# more rd.log 
INSERT INTO `DATABASECHANGELOG` (`DATEEXECUTED`, `AUTHOR`, `xxxx`, `DESCRIPTION`, `COMMENTS`, `MD5SUM`, `ID`, `FILENAME`) VALUES (NOW(), 'rding', '1.9.3', 'Custom 
 SQL', '', '4ac9fbf5222bc344362ccdecbc072', '250.1.1', 'changelogs/myIDENTITY/250/xxxx.xml') 
INSERT INTO `DATABASECHANGELOG` (`DATEEXECUTED`, `AUTHOR`, `xxxx`, `DESCRIPTION`, `COMMENTS`, `MD5SUM`, `ID`, `FILENAME`) VALUES (NOW(), 'rding', '1.9.3', 'Custom 
 SQL', 'Create new table for email change record', '8463e1cf4ba029e3ace675d3e69a71d2', '250.1.2', 'changelogs/myIDENTITY/250/xxxx.xml')

奇怪了,2边的都是一样子的。这个错误怎么判断?

6 去看下主从关于这个数据记录的录入时间。 
从库上面: 
mysql> select * from DATABASECHANGELOG where AUTHOR='rding' and ID='250.1.1' and FILENAME='changelogs/myIDENTITY/250/xxxx.xml'\G; 
*************************** 1. row *************************** 
          ID: 250.1.1 
      AUTHOR: rding 
    FILENAME: changelogs/myIDENTITY/250/xxxx.xml 
DATEEXECUTED: 2013-08-12 20:41:22 
      MD5SUM: 4ac9fbf5222bc344362ccdecbc072 
 DESCRIPTION: Custom SQL 
    COMMENTS:  
         TAG: NULL 
   xxxx: 1.9.3 
1 row in set (0.00 sec)

ERROR:  
No query specified 
mysql>

主库上面 : 
mysql> select * from DATABASECHANGELOG where AUTHOR='rding' and ID='250.1.1' and FILENAME='changelogs/myIDENTITY/250/xxxx.xml'\G; 
*************************** 1. row *************************** 
          ID: 250.1.1 
      AUTHOR: rding 
    FILENAME: changelogs/myIDENTITY/250/xxxx.xml 
DATEEXECUTED: 2013-08-12 19:54:29 
      MD5SUM: 4ac9fbf5222bc344362ccdecbc072 
 DESCRIPTION: Custom SQL 
    COMMENTS:  
         TAG: NULL 
   xxxx: 1.9.3 
1 row in set (0.02 sec)

ERROR:  
No query specified

mysql>  
看DATEEXECUTED时间字段都是8月12日录入的,可惜我的db server由于磁盘有限,只保存了近期的binlog,而且现在主库上面最早的binlog就是出错的那个mysql-bin.000152

7 最后一招,去看从库的binlog,看是否近期有人insert了这条记录 
[root@eanshlt2mydbc004db002 data]# cp mysql-bin.004* /tmp/ 
[root@eanshlt2mydbc004db002 tmp]# mysqlbinlog mysql-bin.004268 > 1.log 
[root@eanshlt2mydbc004db002 tmp]# grep  'rding' 1.log > rd1.log 
[root@eanshlt2mydbc004db002 tmp]# ll rd1.log 
-rw-r--r-- 1 root root 0 Sep  3 17:47 rd1.log 
空的,第一个日志没有录入操作

[root@eanshlt2mydbc004db002 tmp]# mysqlbinlog mysql-bin.004269 > 2.log 
[root@eanshlt2mydbc004db002 tmp]# grep  'rding' 2.log > rd2.log 
[root@eanshlt2mydbc004db002 tmp]# ll rd2.log 
-rw-r--r-- 1 root root 0 Sep  3 17:48 rd2.log 
[root@eanshlt2mydbc004db002 tmp]#  
空的,第二个日志没有录入操作

[root@eanshlt2mydbc004db002 tmp]# mysqlbinlog mysql-bin.004270 > 3.log 
[root@eanshlt2mydbc004db002 tmp]# grep  'rding'  3.log > rd3.log 
[root@eanshlt2mydbc004db002 tmp]# ll rd3.log 
-rw-r--r-- 1 root root 0 Sep  3 17:49 rd3.log 
[root@eanshlt2mydbc004db002 tmp]#  
空的,第三个日志没有录入操作

[root@eanshlt2mydbc004db002 tmp]# mysqlbinlog mysql-bin.004271 > 4.log 
ERROR: Error in Log_event::read_log_event(): 'read error', data_len: 438, event_type: 2 
[root@eanshlt2mydbc004db002 tmp]# grep  'rding' 4.log > rd4.log 
[root@eanshlt2mydbc004db002 tmp]# ll rd4.log 
-rw-r--r-- 1 root root 0 Sep  3 17:50 rd4.log 
空的,第四个日志没有录入操作

这里解析报错了,解决方案,记录在如此 
  http://blog.csdn.net/mchdba/article/details/11011229 
[root@eanshlt2mydbc004db002 tmp]# mysqlbinlog mysql-bin.004272 > 5.log 
[root@eanshlt2mydbc004db002 tmp]# grep  'rding' 5.log > rd5.log 
[root@eanshlt2mydbc004db002 tmp]# ll rd5.log 
-rw-r--r-- 1 root root 0 Sep  3 18:07 rd5.log 
[root@eanshlt2mydbc004db002 tmp]#  
空的,第五个日志没有录入操作

解析了从库的5个日志,都没有看到这条纪律的insert操作,问题到此卡住了,原因何在?这边开发的兄弟们已经在催了,我只要skip之后从库重新做了。 

mysql> stop slave; 
set global sql_slave_skip_counter=1; 
start slave; 
show slave status\G 
Query OK, 0 rows affected (0.09 sec)

mysql> set global sql_slave_skip_counter=1; 
Query OK, 0 rows affected (0.00 sec)

mysql> start slave; 
Query OK, 0 rows affected (0.00 sec) 
mysql> show slave status\G 
*************************** 1. row *************************** 
               Slave_IO_State: Waiting for master to send event 
                  Master_Host: xxxx0402.china.online.ea.com 
                  Master_User: replication 
                  Master_Port: 3306 
                Connect_Retry: 60 
              Master_Log_File: mysql-bin.000184 
          Read_Master_Log_Pos: 27865900 
               Relay_Log_File: mysql-relay-bin.000495 
                Relay_Log_Pos: 253 
        Relay_Master_Log_File: mysql-bin.000171 
             Slave_IO_Running: Yes 
            Slave_SQL_Running: Yes 
              Replicate_Do_DB:  
          Replicate_Ignore_DB:  
           Replicate_Do_Table:  
       Replicate_Ignore_Table:  
      Replicate_Wild_Do_Table:  
  Replicate_Wild_Ignore_Table:  
                   Last_Errno: 0 
                   Last_Error:  
                 Skip_Counter: 0 
          Exec_Master_Log_Pos: 107 
              Relay_Log_Space: 8000 
              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: 3434734 
Master_SSL_Verify_Server_Cert: No 
                Last_IO_Errno: 0 
                Last_IO_Error:  
               Last_SQL_Errno: 0 
               Last_SQL_Error:  
  Replicate_Ignore_Server_Ids:  
             Master_Server_Id: 1 
1 row in set (0.11 sec)

mysql>

mysql主从复制错误:Last_SQL_Error: Error 'Duplicate entry '327' for key 'PRIMARY'' on query. Default database: 'xxx'. Query: 'insert into的更多相关文章

  1. 1062 Error 'Duplicate entry '1438019' for key 'PRIMARY'' on query

    mysql主从库同步错误:1062 Error 'Duplicate entry '1438019' for key 'PRIMARY'' on querymysql主从库在同步时会发生1062 La ...

  2. Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry 'qingmu' for key 'PRIMARY'

    ### Error updating database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolatio ...

  3. com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '88888888' for key 'PRIMARY'

    严重: Servlet.service() for servlet jsp threw exceptioncom.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityC ...

  4. Mysql错误:Duplicate entry '127' for key 'PRIMARY'的解决方法

    有时候真是挺幸运,正当我自以为是地认为掌握了某个知识点的时候,现实就会马上出现另外一个问题,让我知道之前的认知是不全面的. 正如我上篇博文中所述,如果一个自增字段达到了上限,而且继续向里面插入数据的话 ...

  5. 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='%' whe ...

  6. MySQL关于Duplicate entry '1' for key 'PRIMARY'错误

    今天复习MySQL遇到Duplicate entry '1' for key 'PRIMARY'错误. 原因是主键值为'1'的数据已经存在,主键是唯一的,不可重复.

  7. Mysql 错误:Duplicate entry '0' for key 'PRIMARY'

    [1]添加数据报错:Duplicate entry '0' for key 'PRIMARY' (1)问题现象 SQL 语句如下: DROP TABLE test_distinct; CREATE T ...

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

    OS: centos 6.3DB: 5.5.14 测试创建yoon测试表,没有主键,没有索引,基础数据内容如下: mysql> select * from yoon;+----+-------- ...

  9. mysql Duplicate entry '9223372036854775807' for key 'PRIMARY'

    mysql插入数据报错提示: ERROR 1062(23000) Duplicate entry  '9223372036854775807' for key 'PRIMARY' 发现问题果断 直接 ...

随机推荐

  1. centOS 6.4挂载centOS分区

    今天想用centOS打开在windows下编辑的emacs笔记,发现好像不可以自动挂载nfts分区,搜了一下,发现一大坨,还是发个文来标记下好: 首先,安装rpmforge软件库的源 命令行下输入下面 ...

  2. Facade外观模式 笔记

    Facede模式: 把内部系统复杂隐藏,提供一个方便统一的接口. 微波炉在界面简单操作下就可以烹饪出美味佳肴, 微波炉内部运作原理,各个组件互相交互运作,使用者并不需要关心.  而且关心的话可能没有多 ...

  3. 【服务器运维】Windows Server 2008 R2 下配置证书服务器和HTTPS

    前言 2017年1月1日起App Store上的所有App应用将强制开启ATS功能. 苹果的ATS(App Transport Security)对服务器硬性3点要求: ① ATS要求TLS1.2或者 ...

  4. Python logging模块详解

    简单将日志打印到屏幕: import logging logging.debug('debug message') logging.info('info message') logging.warni ...

  5. [Javascript] Advanced Function Scope

    Something like 'for' or 'while', 'if', they don't create a new scope: ,,]; ; i < ary.length; i++) ...

  6. 打勾显示输入的密码 --EditText与setTransformationMethod

    实现目标: 实现原理: 为CheckBox添加一个监听器事件; 实现的源码: package edu.cquptzx.showPassword; import android.app.Activity ...

  7. yii 自动生成的内容,分页信息(Displaying 1-10 of 15 results.)如何修改或是yii cgridview template summary

    问的白一点就是 Displaying 1-10 of 15 results 如何翻译 如果搜索的话, 搜这个会出来很多内容 yii cgridview template summary 好了,其他不说 ...

  8. NYOJ737

    题意:给n堆石子,按照顺序排列,只能相邻两堆石子合并,求最后合并为一堆时所花费的最小代价,石子合并代价为两堆石子之和. 输入: n(石子堆数) Xi(每堆石子个数) 输出: T(最小代价) 思路:经典 ...

  9. Namespace declaration statement has to be the very first

    Namespace declaration statement has to be the very first statement in the script 我新建了一个Homea模块,并把Hom ...

  10. CDN的全称是Content Delivery Network,即内容分发网络

    CDN的全称是Content Delivery Network,即内容分发网络 http://baike.baidu.com/link?url=Wd-IGGgslfJemdpuT3Y0BUi88RPQ ...