Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm uploading data to a db (mysql 5.1.42) from a dump file using mysql command line and get duplicate key error.

This is the format I use:

/mnt/temp# mysql -u username -p -h url_of_db_master -D farm2 < db_dump_part_file_a

Hoe can I tell mysql to ignore duplicate keys?

Thanks !

share|improve this question
up vote 2 down vote accepted

You'll have to decide what you want to happen when a duplicate is found, because you can:

Since mysqldump usually dumps each table in a single insert statement, you can easily just add those keywords in the dump file.

See this SO post for a more in-depth discussion on the pros and cons of the two possiblities.

share|improve this answer
Thanks Matt, This is a large dump and I cant replace the inserts. I was hopeing there is some option that I can give the mysql command prompt that tells it to ignore the errors. Most of the data is statistic so losing a few rows is OK. – Nir Apr 23 '12 at 16:25
@Nir what do you mean by large -- lots of rows or lots of tables? You'll have to make one change for each table, regardless of number of rows. If you're only dumping one table, then you have to make one change. – Matt Fenwick Apr 23 '12 at 16:29

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.