duplicate entry at key primary mysql
My program is really simple it inserts the same value in one column and updates the timestamp and date on another column. It also has an auto incrementing ID column that acts as the table's primary key.
+-------+------------+------+-----+-------------------+-----------------------------+
| Field | Type | Null | Key | Default | Extra |
+-------+------------+------+-----+-------------------+-----------------------------+
| id | bigint(20) | NO | PRI | NULL | au开发者_StackOverflow社区to_increment |
| Power | float | YES | | NULL | |
| dt | timestamp | NO | | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |
+-------+------------+------+-----+-------------------+-----------------------------+
at the moment I'm stuck with id = 4000
Power = 40996
and dt = recent date time
As soon as i try to run a command that inserts data into the table, I get an error that states
duplicate entry '4971' for key 'primary'
check table:
+----------------+-------+----------+-----------------------------------------------------------+
| Table | Op | Msg_type | Msg_text |
+----------------+-------+----------+-----------------------------------------------------------+
| newdb.newmeter | check | warning | Table is marked as crashed |
| newdb.newmeter | check | warning | 19 clients are using or haven't closed the table properly |
| newdb.newmeter | check | warning | Size of datafile is: 68816 Should be: 68663 |
| newdb.newmeter | check | error | Found 4048 keys of 4039 |
| newdb.newmeter | check | error | Corrupt |
+----------------+-------+----------+-----------------------------------------------------------+
Backup your data. If you can afford to shutdown mysqld you should do it and use myisamchk to repair table. If it is not an option try doing FLUSH TABLES; and REPAIR TABLE newmeter; Be prepared for data in your table being not very accurate.
精彩评论