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

与世无争的帅哥 提交于 2019-12-22 06:56:30

问题


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


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/905894/how-to-import-sql-dump-to-a-table-without-overwriting-duplicate-fields

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!