`
LJ你是唯一LT
  • 浏览: 243406 次
社区版块
存档分类
最新评论

Last_SQL_Error: Error 'Duplicate entry '1' for key 'PRIMARY''

阅读更多
[size=small]-实际遇到的问题:
Last_SQL_Error: Error 'Duplicate entry '1' for key 'PRIMARY'' on query. Default database: 'antiy_bbs'.
Query: 'INSERT INTO bbs_common_searchindex SET `srchmod`='2' , `keywords`='apk版本' , `searchstring`='forum|title|YXBr54mI5pys|0||\\\'65\\\',\\\'55\\\',\\\'70\\\',\\\
'69\\\',\\\'71\\\',\\\'72\\\',\\\'73\\\',\\\'74\\\',\\\'2\\\',\\\'48\\\',\\\'38\\\',\\\'67\\\',\\\'47\\\',\\\'79\\\',\\\'56\\\',\\\'58\\\',\\\'59\\\',\\\'66\\\',\\\'
51\\\',\\\'60\\\',\\\'53\\\',\\\'68\\\',\\\'77\\\',\\\'75\\\',\\\'76\\\',\\\'78\\\',\\\'63\\\'|0|0|all|||0' , `useip`='192.168.10.241' , `uid`='54' ,
`dateline`='1420450904' , `expiration`='1420454504' , `num`='0' , `ids`='0''
从报错来看,应该是插入的值违反了主键的约束,但看表结构,主键是自增类型,就不晓得哪里出了问题


主库可看到插入了两条记录,后做了truncate
[root@newmysql5 mysql]# mysqlbinlog mysql-bin.000008|grep bbs_common_searchindex
INSERT INTO bbs_common_searchindex SET `srchmod`='2' , `keywords`='apk版本' , `searchstring`='forum|title|YXBr54mI5pys|0||\\\'65\\\',\\\'55\\\',\\\'70\\\',\\\'69\\\',\\\'71\\\',\\\'72\\\',\\\'73\\\',\\\'74\\\',\\\'2\\\',\\\'48\\\',\\\'38\\\',\\\'67\\\',\\\'47\\\',\\\'79\\\',\\\'56\\\',\\\'58\\\',\\\'59\\\',\\\'66\\\',\\\'51\\\',\\\'60\\\',\\\'53\\\',\\\'68\\\',\\\'77\\\',\\\'75\\\',\\\'76\\\',\\\'78\\\',\\\'63\\\'|0|0|all|||0' , `useip`='192.168.10.241' , `uid`='54' , `dateline`='1420450904' , `expiration`='1420454504' , `num`='0' , `ids`='0'
INSERT INTO bbs_common_searchindex SET `srchmod`='2' , `keywords`='liqintao' , `searchstring`='forum|title|bGlxaW50YW8=|0||\\\'65\\\',\\\'55\\\',\\\'70\\\',\\\'69\\\',\\\'71\\\',\\\'72\\\',\\\'73\\\',\\\'74\\\',\\\'2\\\',\\\'48\\\',\\\'38\\\',\\\'67\\\',\\\'47\\\',\\\'79\\\',\\\'56\\\',\\\'58\\\',\\\'59\\\',\\\'66\\\',\\\'51\\\',\\\'60\\\',\\\'53\\\',\\\'68\\\',\\\'77\\\',\\\'75\\\',\\\'76\\\',\\\'78\\\',\\\'63\\\'|0|0|all|||0' , `useip`='192.168.10.241' , `uid`='54' , `dateline`='1420451052' , `expiration`='1420454652' , `num`='0' , `ids`='0'
TRUNCATE bbs_common_searchindex

而从库只看到insert into,而没有truncate,所以查询记录还有2条,应该是插入的时候卡住了就没往下走。


mysql> show create table bbs_common_searchindex;
+------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table                  | Create Table                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
+------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| bbs_common_searchindex | CREATE TABLE `bbs_common_searchindex` (
  `searchid` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `srchmod` tinyint(3) unsigned NOT NULL,
  `keywords` varchar(255) NOT NULL DEFAULT '',
  `searchstring` text NOT NULL,
  `useip` varchar(15) NOT NULL DEFAULT '',
  `uid` mediumint(10) unsigned NOT NULL DEFAULT '0',
  `dateline` int(10) unsigned NOT NULL DEFAULT '0',
  `expiration` int(10) unsigned NOT NULL DEFAULT '0',
  `threadsortid` smallint(6) unsigned NOT NULL DEFAULT '0',
  `num` smallint(6) unsigned NOT NULL DEFAULT '0',
  `ids` text NOT NULL,
  PRIMARY KEY (`searchid`),
  KEY `srchmod` (`srchmod`) USING BTREE
) ENGINE=MyISAM DEFAULT CHARSET=utf8 |
+------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

mysql> show index from bbs_common_searchindex;
+------------------------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table                  | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+------------------------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| bbs_common_searchindex |          0 | PRIMARY  |            1 | searchid    | A         |           0 |     NULL | NULL   |      | BTREE      |         |               |
| bbs_common_searchindex |          1 | srchmod  |            1 | srchmod     | A         |        NULL |     NULL | NULL   |      | BTREE      |         |               |
+------------------------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
2 rows in set (0.00 sec)

用网上介绍的方法跳过之后,
stop slave;
set global sql_slave_skip_counter=1;
start slave;

mysql> show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.12.101
                  Master_User: repli
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000008
          Read_Master_Log_Pos: 48320168
               Relay_Log_File: mysql-relay-bin.000006
                Relay_Log_Pos: 4840169
        Relay_Master_Log_File: mysql-bin.000008
             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: 4841595
              Relay_Log_Space: 48321003
              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: 34552   ---这里却在持续增大
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: 100
                  Master_UUID: 14bfd13a-1920-11e4-ac07-000c296c30fd
             Master_Info_File: /var/lib/mysql/master.info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: altering table   ---显示正在变更表
           Master_Retry_Count: 86400
                  Master_Bind:
      Last_IO_Error_Timestamp:
     Last_SQL_Error_Timestamp:
               Master_SSL_Crl:
           Master_SSL_Crlpath:
           Retrieved_Gtid_Set:
            Executed_Gtid_Set:
                Auto_Position: 0
1 row in set (0.00 sec)

mysql> use antiy_bbs
Database changed
mysql> select count(*) from bbs_common_searchindex;  --从库看到还有2条记录,而主库是0
+----------+
| count(*) |
+----------+
|        2 |
+----------+
1 row in set (0.00 sec)

mysql> select * from bbs_common_searchindex;
Empty set (0.00 sec)

mysql> select count(*) from bbs_common_searchindex;   ---等待了一会之后,记录消失,同步恢复。
+----------+
| count(*) |
+----------+
|        0 |
+----------+
1 row in set (0.00 sec)

mysql> show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.12.101
                  Master_User: repli
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000008
          Read_Master_Log_Pos: 49058519
               Relay_Log_File: mysql-relay-bin.000007
                Relay_Log_Pos: 10539748
        Relay_Master_Log_File: mysql-bin.000008
             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: 49058519
              Relay_Log_Space: 49057429
              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: 0
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: 100
                  Master_UUID: 14bfd13a-1920-11e4-ac07-000c296c30fd
             Master_Info_File: /var/lib/mysql/master.info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
           Master_Retry_Count: 86400
                  Master_Bind:
      Last_IO_Error_Timestamp:
     Last_SQL_Error_Timestamp:
               Master_SSL_Crl:
           Master_SSL_Crlpath:
           Retrieved_Gtid_Set:
            Executed_Gtid_Set:
                Auto_Position: 0
1 row in set (0.00 sec)


mysql> show variables like 'sql_slave_skip_counter';  --退出会话后,自动变回原来的0,因此不用修改。
+------------------------+-------+
| Variable_name          | Value |
+------------------------+-------+
| sql_slave_skip_counter | 0     |
+------------------------+-------+
1 row in set (0.00 sec)
[/size]
分享到:
评论

相关推荐

    Last_Errno: 1062,Last_Error: Error Duplicate entry

    在这个具体的问题场景中,我们可以看到错误信息提示了“Error Duplicate entry '250.1.1-rding-changelogs/myIDENTITY/250/xxxx.xml' for key 'PRIMARY'”,这表明尝试插入的数据在主键上与现有记录重复。...

    mysql #1062 –Duplicate entry ‘1’ for key ‘PRIMARY’

    碰到了 #1062 – Duplicate entry ‘1′ for key ‘PRIMARY’ 当时那个急啊,原本的数据我已经全部删除了,没办法只有请求万能的百度了。我找了大半天终于给我给我找到了。兴奋ing,马上测试,O(∩_∩)O哈哈~成功了...

    SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry ‘a3b6420a-6’ for key ‘callId’

    "SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'a3b6420a-6724-11ea-b2a3-d773d1d6999f' for key 'callId'\nThe SQL being executed was: INSERT INTO `ly_call` (`call_id`, `mobile`, ...

    U盘只读程序源码源码

    ERROR_DUPLICATE_SERVICE_NAME: sInfo := 'ERROR_DUPLICATE_SERVICE_NAME'; ERROR_INVALID_HANDLE: sInfo := 'ERROR_INVALID_HANDLE'; ERROR_INVALID_NAME: sInfo := 'ERROR_INVALID_NAME'; ERROR_INVALID_...

    mysql error:#1062 Duplicate entry ‘***′ for key 1问题解决方法

    MySQL 错误 #1062 - "Duplicate entry '***' for key 1" 是一个常见的数据库异常,通常表示尝试插入或更新的数据违反了唯一性约束。在这个特定的情况下,问题出现在一个具有自动增长特性的 `id` 字段上。这个错误...

    Multimedia MCI错误返回码详解(包括mciSendString)

    * MCIERR_ILLEGAL_FOR_AUTO_OPEN:自动打开时非法 * MCIERR_FILENAME_REQUIRED:文件名必需 * MCIERR_EXTRA_CHARACTERS:多余字符 * MCIERR_DEVICE_NOT_INSTALLED:设备未安装 * MCIERR_GET_CD:获取CD * MCIERR_SET...

    mysql #1062 –Duplicate entry '1' for key 'PRIMARY'

    标题中的“mysql #1062 –Duplicate entry '1' for key 'PRIMARY'”是一个常见的MySQL错误信息,意味着在尝试插入新的数据记录时,遇到了主键冲突。主键是数据库表中唯一标识每条记录的一列或多列,其值必须在表内...

    IAR编译 Error[Li006]: duplicate definitions for

    在IAR编译环境中,Error[Li006]是一个常见的错误提示,它指出在编译过程中发现了重复的定义。这个错误通常是由于源代码中某个符号(如变量、函数、结构体等)在不同的源文件中被多次定义导致的。在解决这类问题时,...

    CMPP2.0-Java源代码带工具.rar

    3 = TRS_SEQ_DUPLICATE : 消息序号重复 4 = TRS_PACKET_LEN_ERR : 消息长度错 5 = TRS_FEE_ERR : 资费错 6 = TRS_MSG_LEN_ERR : 超过最大信息长 7 = TRS_SRV_CODE_ERR : 业务代码错 8 = TRS_FLUX_ERR : ...

    krb5-devel-1.15.1-50.el7.x86-64的子依赖包

    1、 keyutils-libs-devel-1.5.8-3.el7.x86_64.rpm 2、 libcom_err-devel-1.42.9-19.el7.x86_64.rpm 3、 libkadm5-1.15.1-50.el7.x86_64.rpm 4、 libselinux-devel-2.5-15.el7.x86_64.rpm 5、 libverto-devel-0.2.5-4...

    Framework not found IOSurface for architecture arm64(不能设为免费?)

    在iOS应用开发中,"Framework not found IOSurface for architecture arm64" 是一个常见的构建错误,这通常发生在尝试编译或运行项目时,系统无法找到指定的架构(arm64)所需的IOSurface框架。该问题可能由多种原因...

    Quartz定时任务常用的11张数据库脚本表结构

    1. **QRTZ_JOB_DETAILS**:此表存储所有Job的详细信息,如Job类名、Job数据映射等。每个Job实例在此表中对应一条记录,Job的唯一标识由`SCHED_NAME`(调度器实例名)和`JOB_NAME`(Job名)及`JOB_GROUP`(Job组名)...

    代码审计工具Findbugs自动检查CheckList及配置方法

    - **DBDB_DUPLICATE_BRANCHES/DBDB_DUPLICATE_SWITCH_CLAUSES**:重复的代码分支可能表示代码冗余或错误,应检查并优化代码。 - **DEDE_MIGHT_IGNORE**:捕获的异常未处理,建议提供适当的异常处理。 - **DLSDLS_...

    android studio创建9.patch图片,使用时出现`Error: Duplicate resources`

    android studio创建9.patch图片,使用时出现Error: Duplicate resources 笔者运行环境:MacOs Catalina , android studio 3.6.3 原创文章 5获赞 2访问量 249 关注 私信 展开阅读全文 作者:徐州捕快

    Python MongoDB 插入数据时已存在则不执行,不存在则插入的解决方法

    E11000 duplicate key error collection: QQ.Blog index: _id_ dup key: { : “965464518_1301232446” } 后来知道错误的原因是:插入的数据和已有数据的 ID 重复了。 我想要的是:插入一篇日志,如果该日志(ID)...

    oracle常见错误号

    1. ORA-01002:fetch out of sequence - 当游标没有正确地按照执行顺序进行操作时,比如在未调用`OPEN`、`FETCH`或`CLOSE`之前尝试`FETCH`,会出现这个错误。确保在执行`FETCH`前先调用`OPEN`。 2. ORA-00957:...

    mysql5.6ocp 1z0-883.docx

    1. **错误信息**: `Last_SQL_Error: Error 'Duplicate entry '8' for key 'PRIMARY'' on query. Default database: 'mydb'. Query: 'insert into mytable VALUES('8', 'George')'` - 这表示在插入数据到`mytable`表...

    AP6212最新驱动源码 bcmdhd.1.579.77.41.x.7z

    这个标题提到的"AP6212最新驱动源码 bcmdhd.1.579.77.41.x.7z"是一个压缩包文件,其中包含了AP6212驱动程序的源代码,版本号为1.579.77.41.x。这个驱动程序的源代码是进行系统移植、调试和自定义配置的关键,对于...

Global site tag (gtag.js) - Google Analytics