我有一个mysqldump备份我的mysql数据库,包括我们所有的表,这是大约440兆。我只想从mysqldump中恢复其中一个表的内容。这可能吗?从理论上讲,我可以只删除重建我想要的表的部分,但我甚至不知道如何有效地编辑这种大小的文本文档。


当前回答

SQL块被“表my_table的表结构”和“转储表my_table的数据”阻塞。

您可以如下所示使用Windows命令行获取各个部分的行号。根据需要调整搜索字符串。

查找/n "for table ' " sql.txt

将返回以下内容:

---------- SQL.TXT

[4384]——my_table的表结构

[4500]——转储表my_table的数据

[4514]——表some_other_table的表结构

... 等。

这就得到了你需要的行号……现在,如果我知道如何使用它们……调查。

其他回答

您可以使用如下所示的终端线导入单个表。 这里导入单个用户表到特定的数据库。

mysql -u root -p -D my_database_name < var/www/html/myproject/tbl_user.sql

不管怎样,任何这样做的进程都必须遍历转储的整个文本,并以某种方式解析它。我只要grep

INSERT INTO `the_table_i_want`

并将输出导入mysql。看一下之前转储中的第一个表,以确保您以正确的方式获取INSERT。

编辑:好的,这次格式正确。

这能更容易做到吗?我是这样做的:

创建一个临时数据库(例如restore):

Mysqladmin -u root -p create restore

恢复临时数据库中的完整转储:

Mysql -u root -p——one-database restore < fulldump.sql

转储需要恢复的表:

Mysqldump恢复mytable

在另一个数据库中导入表:

Mysql -u root -p database < mytable.sql

Get a decent text editor like Notepad++ or Vim (if you're already proficient with it). Search for the table name and you should be able to highlight just the CREATE, ALTER, and INSERT commands for that table. It may be easier to navigate with your keyboard rather than a mouse. And I would make sure you're on a machine with plenty or RAM so that it will not have a problem loading the entire file at once. Once you've highlighted and copied the rows you need, it would be a good idea to back up just the copied part into it's own backup file and then import it into MySQL.

您可以使用vi编辑器。类型:

vi -o mysql.dump mytable.dump

打开全部转储mysql。Dump和一个新文件mytable.dump。 通过按/找到合适的insert into line,然后键入一个短语,例如:"insert into ' mytable ' ",然后使用yy复制这一行。按ctrl+w然后向下方向键切换到下一个文件,用pp粘贴复制的行。最后输入:wq保存新文件,用:q保存。

注意,如果您使用多个插入转储了数据,您可以使用Nyy一次复制(yank)所有数据,其中N是要复制的行数。

我用一个920 MB大小的文件做了这件事。