MySQL:密钥'PRIMARY'的重复条目

时间:2015-06-26 13:17:42

标签: mysql primary-key

我有下表:

+------+--------+---------+------------+----------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+---------------------+------------+-----------------+----------+----------------+---------+
| Name | Engine | Version | Row_format | Rows     | Avg_row_length | Data_length | Max_data_length | Index_length | Data_free | Auto_increment | Create_time         | Update_time         | Check_time | Collation       | Checksum | Create_options | Comment |
+------+--------+---------+------------+----------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+---------------------+------------+-----------------+----------+----------------+---------+
| logs | MyISAM |      10 | Dynamic    | 34823016 |            237 |  8285517176 | 281474976710655 |    357365760 |       192 |       34823017 | 2015-06-17 21:37:54 | 2015-06-26 15:49:21 | NULL       | utf8_general_ci |     NULL |                |         |
+------+--------+---------+------------+----------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+---------------------+------------+-----------------+----------+----------------+---------+

mysql> show columns from logs;
+--------------------+------------------+------+-----+---------+----------------+
| Field              | Type             | Null | Key | Default | Extra          |
+--------------------+------------------+------+-----+---------+----------------+
| ID                 | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
| ReceivedAt         | datetime         | YES  |     | NULL    |                |
| DeviceReportedTime | datetime         | YES  |     | NULL    |                |
| Facility           | smallint(6)      | YES  |     | NULL    |                |
| Priority           | smallint(6)      | YES  |     | NULL    |                |
| FromHost           | varchar(60)      | YES  |     | NULL    |                |
| Message            | text             | YES  |     | NULL    |                |
| InfoUnitID         | int(11)          | YES  |     | NULL    |                |
| SysLogTag          | varchar(60)      | YES  |     | NULL    |                |
| CustomerID         | bigint(20)       | YES  |     | NULL    |                |
| NTSeverity         | int(11)          | YES  |     | NULL    |                |
| Importance         | int(11)          | YES  |     | NULL    |                |
| EventSource        | varchar(60)      | YES  |     | NULL    |                |
| EventUser          | varchar(60)      | YES  |     | NULL    |                |
| EventCategory      | int(11)          | YES  |     | NULL    |                |
| EventID            | int(11)          | YES  |     | NULL    |                |
| EventBinaryData    | text             | YES  |     | NULL    |                |
| MaxAvailable       | int(11)          | YES  |     | NULL    |                |
| CurrUsage          | int(11)          | YES  |     | NULL    |                |
| MinUsage           | int(11)          | YES  |     | NULL    |                |
| MaxUsage           | int(11)          | YES  |     | NULL    |                |
| EventLogType       | varchar(60)      | YES  |     | NULL    |                |
| GenericFileName    | varchar(60)      | YES  |     | NULL    |                |
| SystemID           | int(11)          | YES  |     | NULL    |                |
| processid          | varchar(60)      | NO   |     |         |                |
| checksum           | int(11) unsigned | NO   |     | 0       |                |
+--------------------+------------------+------+-----+---------+----------------+

我想插入一行:

INSERT INTO logs (ID, ReceivedAt, DeviceReportedTime, Facility,
 Priority, FromHost, Message, InfoUnitID, SysLogTag, CustomerID,
 NTSeverity, Importance, EventSource, EventUser, EventCategory,
 EventID, EventBinaryData, MaxAvailable, CurrUsage, MinUsage,
 MaxUsage, EventLogType, GenericFileName, SystemID)
VALUES ('34823017',
        '2015-06-26T15:06:02+03:00',
        '2015-06-26T15:06:38+03:00',
        '22',
        '6',
        'po-sv-bus-01v',
        'type=SYSCALL msg=audit(1435320388.132:831638): arch=c000003e syscall=4 success=yes exit=0 a0=7f4bc8616ca0 a1=7f4bd1c10c00 a2=7f4bd1c10c00 a3=0 items=1 ppid=1 pid=3489 auid=286786658 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 ses=204 tty=(none) comm="rsyslogd" exe="/sbin/rsyslogd" subj=unconfined_u:system_r:syslogd_t:s0 key="power-abuse"',
        '1',
        'audit: ',
        '',
        '',
        '',
        '',
        '',
        '',
        '',
        '',
        '',
        '',
        '',
        '',
        '',
        '',
        '');

我正在解决错误:

  

ERROR 1062(23000):关键字'PRIMARY'重复输入'34823017'

虽然没有重复的条目:

mysql> select * from logs where ID = '34823017';

Empty set (0.00 sec)

有人可以帮助我吗?

1 个答案:

答案 0 :(得分:0)

请勿手动设置ID。例如,您可以传递null,然后它将自动递增