简体   繁体   English

如何从使用 sql 后缀压缩的 mysqldump 恢复单个表?

[英]How to restore single table from mysqldump that is gzipped with sql suffix?

I know how to restore table from mysqldump.sql file.我知道如何从 mysqldump.sql 文件中恢复表。 But is it possible to restore single table from mysqldump.sql.gz?但是是否可以从 mysqldump.sql.gz 恢复单个表?

I know that there is very similar question to mine, but I want to restore data from file that is.sql.gz, and I saw only methods with one suffix.我知道我的问题非常相似,但我想从文件中恢复数据,即.sql.gz,我只看到了带有一个后缀的方法。

I also know, that I can just decompress the file, but preferably I would like to restore table without decompressing whole backup.我也知道,我可以只解压缩文件,但最好我想在不解压缩整个备份的情况下恢复表。

I think that you can try with sed command in terminal.我认为您可以在终端中尝试使用 sed 命令。

If your table is named users try to do it like that:如果您的表名为users尝试这样做:

$ sed -n -e '/CREATE TABLE.*`users`/,/Table structure for table/p' mysqldump.sql.gz > users.dump

This will copy the information between CREATE TABLE and next table from your dump to users.dump.这会将 CREATE TABLE 和下一个表之间的信息从您的转储复制到 users.dump。

After that you know what to do;)之后你就知道该怎么做了;)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM