0

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 !

1
  • can you post full query like this, to avoid duplicates since i import large db size around 500mb In this, mysql -u username -p database_name < "/path/file.sql"
    – manigopal
    Commented Jul 19, 2020 at 16:16

1 Answer 1

2

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.

2
  • 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
    Commented Apr 23, 2012 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. Commented Apr 23, 2012 at 16:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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