Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to import SQL dump to a table without overwriting duplicate fields

how do I import a MySQL dump file to a database without overwriting records with the same value?

like image 772
alimango Avatar asked May 25 '09 08:05

alimango


2 Answers

Here is the link to the manual. You can specify whether to replace existing records.

--replace, -r

The --replace and --ignore options control handling of input rows that duplicate existing rows on unique key values. If you specify --replace, new rows replace existing rows that have the same unique key value. If you specify --ignore, input rows that duplicate an existing row on a unique key value are skipped. If you do not specify either option, an error occurs when a duplicate key value is found, and the rest of the text file is ignored.

If you are using phpmyadmin then you will have an option for this in the GUI as well.

like image 135
Shoban Avatar answered Sep 23 '22 02:09

Shoban


You can modify the SQL file and change INSERT INTO to INSERT IGNORE INTO

like image 23
Aminah Nuraini Avatar answered Sep 19 '22 02:09

Aminah Nuraini