Linux 如何将 bzip 的输出通过管道传输到 mysql 以将数据直接从 bzip 文件恢复到数据库中

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11080773/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 06:55:02  来源:igfitidea点击:

How can I pipe output of bzip to mysql to restore data directly from bzipped file into a database

mysqllinuxcommand-linepipedatabase-restore

提问by Sasha

For making a dump of a database directly in bz2 format, I tried zipping the dump file directly using pipes, as follows:

为了直接以 bz2 格式转储数据库,我尝试使用管道直接压缩转储文件,如下所示:

mysqldump -u userName -p myDataBase | bzip2 -c > myDump.sql.bz2

I want to do a similar thing for restore. I can do this using 2 commands as follows: command 1:

我想为恢复做类似的事情。我可以使用 2 个命令执行此操作,如下所示:命令 1:

bzip2 -d myDump.sql.bz2

command 2:

命令 2:

mysql -u userName -p myDataBase < myDump.sql

Wanted: Now I want to use the pipes to restore myDump.sql.bz2to the database myDataBase.

通缉:现在我想使用管道恢复myDump.sql.bz2到数据库myDataBase

回答by Sean McSomething

bzip2 -dc myDump.sql.bz2 | mysql -u userName -p myDatabase- the -c option to bzip2 makes it send output to stdout, which you're already using when you created the dump.

bzip2 -dc myDump.sql.bz2 | mysql -u userName -p myDatabase- bzip2 的 -c 选项使其将输出发送到 stdout,您在创建转储时已在使用该输出。

回答by isqad

try it:

尝试一下:

bzcat dump.sql.bz2 | mysql -u name -p db