How to backup MySQL Database in command line with compression

advertisement

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

Technorati Tags: , , , , , , , , , , ,



Related Post


9 Responses to “How to backup MySQL Database in command line with compression”

  1. Aus says:

    Very good! I’ll use it in my backup script:

    #create (if not exist) backup folder
    mkdir -p /home/aus/project_bak
    cd /home/aus/project_bak

    # backup the project software
    tar cvf $(date +%Y-%0m-%0d_%0H%0M.CPP.bak.tar) /home/aus/Project

    # backup the web application
    tar cvf $(date +%Y-%0m-%0d_%0H%0M.WEB.bak.tar) /var/www

    # Thanks to Techie Corner, back up the database
    mysqldump -hlocalhost -uroot -proot users > $(date +%Y-%0m-%0d_%0H%0M.sql)

  2. pjammer says:

    what kind of ass says not helpful? geeks. I liked this and was helpful.

  3. Nick says:

    obvious but still helpful, thanks

  4. oztrout says:

    works for me … thank you … :)

  5. Stefan says:

    Thanks bro!

  6. vinayak says:

    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

  7. rr says:

    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

  8. Matt says:

    was helpful

  9. aa says:

    not helpful at all!

Leave a Reply