views:

57

answers:

2

I have always done this:

mysqldump -hlocalhost -uuser -ppass MYDATABASE > /home/f/db_backup/MYDATABASE.sql
mysql -uuser -ppass MYDATABASE < MYDATABASE.sql

But, if I do this instead...is this safe? Is this identical to the above???

mysqldump -hlocalhost -uuser -ppass MYDATABASE | gzip > /home/f/db_backup/MYDATABASE.sql.gz
zcat MYDATABASE.sql.gz | mysql -uuser -ppass MYDATABASE
+3  A: 

That's totally fine (and more efficient, of course!) Mysql doesn't see any difference; both methods end up passing uncompressed SQL data.

Delan Azabani
Ok, if my data is lost, you owe me 50 million dollars
TIMEX
If you are risking 50 million dollars worth of data on the answer to a SO question, you owe your boss 50 million dollars.
Amber
If you do lose the data, it'll probably be something out of manual control like power failure/data corruption, that won't be caused by gzipping the data.
Delan Azabani
50 million dollars? Your data is totally safe at the special file `/dev/null`. Even a crash doesn't change the contents of that file :)
extraneon
Thanks all :) Nahh my data is worth like 5 dollars.
TIMEX
A: 

It's safe (mostly) and if you had spare CPU cycles you could add '-C' to your mysqldump to have it compress client <-> server comms which should save you some time on large DBs.
FWIW per db username/password details in ~/.my.cnf of the user who is running the mysqldump command. This way the DB credentials won't be viewable by other users on the system using command like 'ps'.

Martin