Ashesh Shrestha
Ashesh Shrestha

Reputation: 388

Import database in Wamp Server

I want to back up my website to localhost. Well I am new to all PHP and other things.

I opened my website and downloaded my database. Then I created a database in phpMyAdmin on localhost and installed WordPress on it. Now when I try to import the database it shows the follwing error:

error!! #1062 - Duplicate entry '1' for key 'PRIMARY' 

I think I made some mistakes. Is there anything that I should do with selecting collection or something like that while creating the database?

Upvotes: 1

Views: 2742

Answers (3)

M Alam
M Alam

Reputation: 1

I had been facing the same problem for long in WAMP phpMyAdmin server. I went to so many sites and forums and guru's help but most didn't make sense. Some suggested to "add/mark add drop table" and some to "use update in place of insert". These answers were so lackadaisical and untechnical. They never hit on real problem. The real problem lies in WAMP phpMyAdmin. There seems to be a bug in it, which inserts TWO additional lines in the SQL file when one exports an existing database. These lines are the lower two of:

--
-- Database: `xyz`
--
CREATE DATABASE IF NOT EXISTS `xyz` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci;
USE `xyz`;

What happens really is when you export an existing database and then create a blank database there with some other name and then try to export that existing database SQL file is the following: Due to those additional lines, SQL Server tries to create a database with the same name. Hence the duplicate key problem. All you need to do: Open the SQL file with Notepad Plus or any other editor and delete said two lines, keeping only:

--
-- Database: `xyz`
--

Then save the file and import it to your blank database with whatever name you want. Hopefully it will solve the problem.

Upvotes: 0

RiggsFolly
RiggsFolly

Reputation: 94642

This can happen if you did your backup without ticking the add DROP TABLE option, or when you try to do the restore more than once.

Never mind, just use phpMyAdmin to drop ( thats delete ) all the tables within that database and try the resore again.

Upvotes: 1

Reign
Reign

Reputation: 289

Basically, what it means is that you have 2 things with the PRIMARY number of 1, the table must most likely be setup with an auto_increment this is where you issue is.

Upvotes: 0

Related Questions