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


当前回答

这个工具可能就是你想要的:tbdba-restore-mysqldump.pl

https://github.com/orczhou/dba-tool/blob/master/tbdba-restore-mysqldump.pl

从数据库转储文件中恢复一个表:

Tbdba-restore-mysqldump.pl -t yourtable -s yourdb -f backup.sql

其他回答

sed -n -e '/-- Table structure for table `my_table_name`/,/UNLOCK TABLES/p' database_file.sql > table_file.sql

这是一种比上面其他解决方案更好的解决方案,因为并非所有SQL转储都包含DROP TABLE语句。这将工作将所有类型的转储。

一个简单的解决方案是仅为希望单独恢复的表创建一个转储。你可以使用mysqldump命令来这样做,语法如下:

mysqldump -u [user] -p[password] [database] [table] > [output_file_name].sql

然后像往常一样导入它,它只会导入转储的表。

表应该在转储和数据库中呈现相同的结构。

`zgrep -a ^"INSERT INTO \`table_name" DbDump-backup.sql.tar.gz | mysql -u<user> -p<password> database_name`

or

`zgrep -a ^"INSERT INTO \`table_name" DbDump-backup.sql | mysql -u<user> -p<password> database_name`

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

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

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

将返回以下内容:

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

[4384]——my_table的表结构

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

[4514]——表some_other_table的表结构

... 等。

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

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.