MySQL import - how to ignore Drop table if row exists?

I exported 2 identical databases (identical in names and table structures) to two .sql files using mysqldump. I want to combine them into one file. However, both databases have a “Drop table” line in front of each table. This means that if I import db1 and then db2, the db1 tables will be deleted before importing the db2 tables.

The files are huge and I cannot open them in the editor. In addition, there are 50 tables in each database.

How can I ignore the decompress table command during mysql import?

+4
source share
3 answers

If you do not want to dump again and you are using Linux, you can go with:

awk '!/^DROP TABLE IF EXISTS/{print}' <dump.file> | mysql <db_name>

If you want to reset the data again, you must pass --skip-add-drop-tablemysqldump to the utility.

+11
source

All you need to do is add an option --skip-add-drop-tablewhen using mysqldump.

$ mysqldump --databases --skip-add-drop-table -u root db1 > /tmp/qqq.2

Thus, the sqlfiles would not have been DROP TABLE IF EXISTS.

see docs mysql on --skip-add-drop-table

+10
source

, , DROP TABLE IDENTICAL.

, , DROP TABLE . mysqldump, http://dev.mysql.com/doc/refman/5.5/en/mysqldump.html

This probably means that you need to use the flag --skip-optif you used the default options (by default it starts as if the flag was sent --opt). Then you need to specify all the flags in --optthat you still want to use.

+1
source

All Articles