patternsqlModerate
Dump of a mysql table on import replaced existing records
Viewed 0 times
dumpreplacedrecordsmysqlexistingtableimport
Problem
I took a dump using mysqldump..
Then I imported the dump in another database having same table, but different records..
The importing db had records from primary_key 1 to 1000, and the exporting db had 5000 to 10,000..
But on import the existing records, ie 1 to 1000 got deleted..
How?? Why?? If it a default behaviour, what options I can give to dump to not let it happen next time..
mysqldump -u... -p... mydb t1 > mydb_table.sqlThen I imported the dump in another database having same table, but different records..
mysql -u...-p... mydb < mydb_tables.sqlThe importing db had records from primary_key 1 to 1000, and the exporting db had 5000 to 10,000..
But on import the existing records, ie 1 to 1000 got deleted..
How?? Why?? If it a default behaviour, what options I can give to dump to not let it happen next time..
Solution
The mysqldump, by default, will drop the table. You should specified the
That way, you only have inserts to deal with. Using
The
--no-create-info option like this:mysqldump -u... -p... --no-create-info --skip-extended-insert mydb t1 > mydb_table.sqlThat way, you only have inserts to deal with. Using
--skip-extended-insert will insert one row at a time. This help deal with duplicate issues, but you will have import like this:mysql -u...-p... --force mydb < mydb_tables.sqlThe
--force option is for the sole purpose of continuing INSERTs in the event a duplicate key is encountered. In that instance, the offending INSERT's error is ignored and on to the next INSERT.Code Snippets
mysqldump -u... -p... --no-create-info --skip-extended-insert mydb t1 > mydb_table.sqlmysql -u...-p... --force mydb < mydb_tables.sqlContext
StackExchange Database Administrators Q#33807, answer score: 13
Revisions (0)
No revisions yet.