Merge Multiple .sql Table Dump Files Into A Single File

主宰稳场 提交于 2021-02-17 22:03:13

问题


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

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