Backup MySQL DB in command line

So you have a website on a dedicated server. You need to backup a database. You tried to backup through PhPMyadmin but it keeps timing out. Here is what you need to do. Backup the database through a terminal session. SSH into your web/MySQL server and run the following commands below.

TO BACKUP:

##Without G Zip Compresssion:
mysqldump -u USERACCOUNT -pYOURPASSWORDGOESHERE YOURDATABASENAMEHERE > latest_backup_061009.sql

##With G Zip Compresssion:
mysqldump -u USERACCOUNT -pYOURPASSWORDGOESHERE YOURDATABASENAMEHERE | gzip -c > latest_backup_061009.sql

TO RESTORE:

##To restore a backup of a database created with mysqldump, you will need to use the mysql command. If your SQL dump file doesn’t contain any “create database” statement use the following command:
mysql -u USERACCOUNTNAME -pYOURPASSWORDGOESHERE YOURDATABASENAMEHERE < latest_backup_061009.sql

##But if it does contain the “create database” statement use the same command without specifying the database name:
mysql -u USERACCOUNTNAME -pYOURPASSWORDGOESHERE < latest_backup_061009.sql

Print Friendly, PDF & Email

Leave a Reply