本文介绍了将多个 .sql 表转储文件合并到一个文件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有数据库 A 和表 b.给定多个 .sql 文件 b1,b2,...,bn 每个对应于 b 的互斥表转储我将如何将所有文件 b1,b2,...,bn 合并到一个 .sql 表文件中?或者我如何将单个文件的导入合并到一个表中?

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?

推荐答案

没有特殊的工具可以做到这一点.您可以简单地连接文件:

There are no special tools to do this. You can simply concatenate the files:

$ cat b1.sql b2.sql b3.sql > b_all.sql

除了这些 .sql 文件的典型内容是 DROP TABLE,然后是 CREATE TABLE,然后是很多 INSERT 语句.如果每个单独的转储文件都是这样格式化的,那么如果你按顺序恢复它们,每个文件都会DROP TABLE并擦除前一个文件导入的数据.

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.

您可以在没有 DROP/CREATE 语句的情况下创建转储文件:

You can create a dump file without the DROP/CREATE statements:

$ mysqldump --no-create-info <database> <table> ...

但是如果您已经有转储文件(不能重新转储它们),并且您想在除第一个文件之外的所有文件中删除 DROP/CREATE 语句:

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

这篇关于将多个 .sql 表转储文件合并到一个文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 12:09