我可以从完整的mysql mysqldump文件还原单个表吗? [英] Can I restore a single table from a full mysql mysqldump file?

查看:303
本文介绍了我可以从完整的mysql mysqldump文件还原单个表吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的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 form 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`/,/CREATE 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文件还原单个表吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆