Knyazev Dmitry
Knyazev Dmitry

Reputation: 1

MySQL: duplicate entry for key 'PRIMARY'

I have the following table:

+------+--------+---------+------------+----------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+---------------------+------------+-----------------+----------+----------------+---------+
| 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       |                |
+--------------------+------------------+------+-----+---------+----------------+

I am trying to insert a row:

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: ',
        '',
        '',
        '',
        '',
        '',
        '',
        '',
        '',
        '',
        '',
        '',
        '',
        '',
        '',
        '');

And I'm geting the error:

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

While there is no duplicate entry:

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

Empty set (0.00 sec)

Can someone help me?

Upvotes: 0

Views: 1919

Answers (1)

Sergey  Dzhus
Sergey Dzhus

Reputation: 50

Don't set the ID manually. You can pass null for example, then it will auto increment

Upvotes: 1

Related Questions