phpMyAdmin export/import results in duplicate primary key error phpMyAdmin export/import results in duplicate primary key error wordpress wordpress

phpMyAdmin export/import results in duplicate primary key error


The original data is still in the database.

If you were working manually you'd send a UPDATE rather than INSERT query with the new values, but since you're doing a batch import, it may just be better to wipe the existing table clean before the import.

DELETE FROM `tblName`;

Be sure to back-up your data, first.


To avoid duplicates you have to use UPDATE instead of INSERT statements. To achieve this in phpMyAdmin, follow these steps:

  1. Select your database in the tree.
  2. OPTIONAL. Go to "Search" tab and search for string you want to replace in all tables. If string is found in several tables only, note their names. This will help to speed up process by updating only the tables which needs updating. This my be important if you have lot of data.
  3. Go to "Export" tab.
  4. In the "Export method:" select "Custom".
  5. OPTIONAL. If you noted the tables which need updating in step 2 above, then in the "Table(s):" section, click "Unselect all" and then select only the tables which need to be updated.
  6. Scroll down to "Data creation options" section, and in the drop box labeled "Function to use when dumping data:" select "UPDATE" (default is "INSERT").
  7. Click "Go".
  8. Open the downloaded SQL dump file.
  9. IMPORTANT! Save the file with a new name for backup purposes before any changes are made.
  10. Use Search & replace function of your editor to change what you want. Then save the file.
  11. In phpMyAdmin go to "Import" tab.
  12. In the "File to import:" section click the "Choose file" button and browse for the edited file. Click GO

You are ready! To check if everything is OK, search the database second time (repeat step 2). You should not find any tables containing your old string.


If you're exporting, that means that the main content stays in the database. So, when you try to insert a new row with the same PRIMARY KEY, which are always UNIQUE, you'll get an error.

Solution: You must delete the row from the table that has the same comment_ID.You must open the PHPMyAdmin and go your table page, and check the row with the ID you want. In this case is 1, which means that it is probabily in the first results page of your table listing. Just click on the red X which appears in the row.

This could also be done by SQL, which could be simple too.

DELETE FROM `wp_comments` WHERE `comment_ID` = 1 LIMIT 1

For this, just select your database in PHPMyAdmin and go to the SQL tab, and insert the code above in the text area.