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 posts:

PHP Programming: The difference between require() and include()
Free FTP Client for Mac OS X / Win XP / Vista
How to import contacts from Mac to Nokia N900
How to do string replace (str_replace) in MySQL
CPAN Error: make test had returned bad status, won't install without force
OpenOffice Calc worksheet tab went missing
How to hide apache2 version number in error page
Symfony: PHP Fatal error: Call to a member function setData()






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

  1. Luis Pichardo says:

    Thank you for the tip, much appreciated. I use to move big MySQL backups and sometimes you cannot handle those with phpmyadmin.

  2. chad says:

    why says not helpful when majority said the better results out of that command?

  3. Chris says:

    Hi,

    Having installed xampp in my pc, I am ready to work on my various large database or dump files before I upload them to the live webhost/server.

    1. Now, how do I load a large database into the database created in phpmyadmin in xampp on my pc using mysql shell command??
    I have tried using phpmyadmin but was not successful due to exceeding the max limit.

    2. once it has been loaded successfully, then I can export or backup this same large database/dump again but this time, I want to backup into smaller parts (say there are total 30 tables and I want to backup into 3 x 10tables ) total 3 parts.
    How can I do this and what’s the shell command path or command strings to do such?

    Thank you in advance for any kind guidance and assistance.

    Regards,
    Chris

  4. 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)

  5. pjammer says:

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

  6. Nick says:

    obvious but still helpful, thanks

  7. oztrout says:

    works for me … thank you … :)

  8. Stefan says:

    Thanks bro!

  9. 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

  10. 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

  11. Matt says:

    was helpful

  12. aa says:

    not helpful at all!

Leave a Reply