问题描述
我有我的 mysql 数据库的 mysqldump 备份,其中包含我们所有的表,大约 440 兆.我只想从 mysqldump 恢复其中一个表的内容.这可能吗?理论上,我可以剪掉重建我想要的表格的部分,但我什至不知道如何有效地编辑这么大的文本文档.
I have a mysqldump backup of my mysql database consisting of all of our tables which is about 440 megs. I want to restore the contents of just one of the tables from the mysqldump. Is this possible? Theoretically, I could just cut out the section that rebuilds the table I want but I don't even know how to effectively edit a text document that size.
推荐答案
你可以尝试使用 sed 来只提取你想要的表.
You can try to use sed in order to extract only the table you want.
假设您的表的名称是 mytable
而文件 mysql.dump
是包含您的巨大转储的文件:
Let say the name of your table is mytable
and the file mysql.dump
is the file containing your huge dump:
$ sed -n -e '/CREATE TABLE.*`mytable`/,/Table structure for table/p' mysql.dump > mytable.dump
这将在文件 mytable.dump
中复制位于 CREATE TABLE mytable
和对应于下一个表的下一个 CREATE TABLE
之间的内容.
This will copy in the file mytable.dump
what is located between CREATE TABLE mytable
and the next CREATE TABLE
corresponding to the next table.
然后您可以调整文件mytable.dump
,其中包含表mytable
的结构和数据(INSERT
的列表)).
You can then adjust the file mytable.dump
which contains the structure of the table mytable
, and the data (a list of INSERT
).
这篇关于我可以从完整的 mysql mysqldump 文件中恢复单个表吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!