phpMyAdmin: MySQL Error 1062 - Duplicate entry

旧巷老猫 提交于 2019-12-07 15:33:04

问题


I connect with user "root" onto my database "test" which I host locally for development. Among others I have the table "ratingcomment". For some reason when I click on the table "ratingcomment" phpMyAdmin shows me the following error:

Fehler

    SQL-Befehl: 

    INSERT INTO  `phpmyadmin`.`pma_history` (

    `username` ,
     `db` ,
     `table` ,
     `timevalue` ,
     `sqlquery`
    )
    VALUES (
    'root',  'test',  'ratingcomment', NOW( ) ,  'SELECT * FROM `ratingcomment`'
    )
    MySQL meldet: 

    #1062 - Duplicate entry '838' for key 'PRIMARY'

I used google to finde out the following

"This indicates that you have a UNIQUE or PRIMARY index on a table, and there is a duplicate value someone on one of the values in one of these indexes."

But I still dont quite understand the error! I use a primary Key, which auto-increments for all of my tables, so there actually shouldnt be a problem with the table. I had another table named "rating" which had a column "comment". Can it be, that this causes problems?


回答1:


Quick fix:

REPAIR TABLE `phpmyadmin`.`pma_history`

If that fails, I'd just truncate/empty the table.

TRUNCATE TABLE `phpmyadmin`.`pma_history`

Although phpmyadmin has it's place in my toolbox, I personally don't use it's internal db.

ADDENDUM

MyISAM tables can easily become corrupted. A couple causes that usually hit me: if the MySQL is not shutdown properly, or if the table has a FULLTEXT index and the stopword file on disk had changed.

Simply stated, the REPAIR just checkes the data file for errors (and depending on your options, makes it usable again) and rewrites the index file. Fair warning: with MyISAM, repairing a table can often toast all your data in that table to make it usable. See doc for more details.

A google search pertaining to this pma table being corrupted lead me to this.




回答2:


This appears to be an internal error. You've issued this query:

SELECT * FROM `ratingcomment`

phpMyAdmin tries to write such action in its internal event log and it fails. If you Google for pma_history you'll find several references to such table being corrupted.

My advice is that you find another SQL client (such as HeidiSQL) and try to repair the phpMyAdmin database.




回答3:


I know this is kinda late but I had the same problem and wanted to share what I did.

In PhpMyAdmin, I went to the table's Operation tab, and just incremented the AUTO_INCREMENT value under Table options and inserted a dummy record.



来源:https://stackoverflow.com/questions/4337781/phpmyadmin-mysql-error-1062-duplicate-entry

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!