How to backup MySQL Database in command line with compression

For those who looking for way to backup mysql database,
you can use mysqldump to backup mysql database.
Below is the script example to backup mysql database in command line:-
$ mysqldump -h localhost -u username -p database_name > backup_db.sql
If your mysql database is very big, you might want to compress your sql file.
Just use the mysql backup command below and pipe the output to gzip,
then you will get the output as gzip file.
$ mysqldump -u username -h localhost -p database_name | gzip -9 > backup_db.sql.gz
If you want to extract the .gz file, use the command below:-
$ gunzip backup_db.sql.gz
Tags: backup mysql, backup mysql command line, backup mysql db, backup mysql server, command line, command line backup mysql database, command line backup mysql db, db, mysql, mysql db, mysql server, SQL
Posted at October 5th, 2006 by chua
If you think this article helps you to solve your problem and clear your headache, feel free to buy me a drink :)



June 12th, 2007 at 11:49 am
not helpful at all!
January 9th, 2008 at 12:43 am
was helpful
July 2nd, 2008 at 9:21 am
well, im using mysql query browser, and i want to update fields and tables, so.. how can i back up my old field contents?? i dont want to retype them
August 12th, 2008 at 7:08 pm
well, im using mysql query browser, and i want to update fields and tables, so.. how can i back up my old field contents?? i dont want to retype them
June 19th, 2009 at 3:01 pm
Thanks bro!
November 5th, 2009 at 2:39 am
obvious but still helpful, thanks
December 22nd, 2009 at 11:50 pm
what kind of ass says not helpful? geeks. I liked this and was helpful.