Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

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:

bzip2 -d myDump.sql.bz2

command 2:

mysql -u userName -p myDataBase < myDump.sql

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

like image 286
Sasha Avatar asked Jun 18 '12 10:06

Sasha


2 Answers

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.

like image 99
Sean McSomething Avatar answered Nov 13 '22 08:11

Sean McSomething


try it:

bzcat dump.sql.bz2 | mysql -u name -p db
like image 16
isqad Avatar answered Nov 13 '22 08:11

isqad