问题
Suppose I have database A and Table b. Given multiple .sql files b1,b2,...,bn each of which corresponds to a mutually exclusive table dump of b how would I go about combining all files b1,b2,...,bn into a single .sql table file? Or how would I combine the import of the individual files into a single table?
回答1:
There are no special tools to do this. You can simply concatenate the files:
$ cat b1.sql b2.sql b3.sql > b_all.sql
Except that the typical content of these .sql files is a DROP TABLE, then a CREATE TABLE, then a lot of INSERT statements. If each of the individual dump files is formatted like that, then if you restore them in sequence, each will DROP TABLE and erase the data imported by the preceding file.
You can create a dump file without the DROP/CREATE statements:
$ mysqldump --no-create-info <database> <table> ...
But if you have the dump files already (can't re-dump them), and you want to get rid of the DROP/CREATE statements in all but the first file:
$ ( cat b1.sql ; cat b2.sql b3.sql | sed -e '/^DROP TABLE/,/^-- Dumping data/d' ) > b_all.sql
来源:https://stackoverflow.com/questions/17582660/merge-multiple-sql-table-dump-files-into-a-single-file