Monday, March 30, 2009

Backup your SQL Database using SSH

I just found out about this very easy, efficient and incredibly fast way to back up SQL databases. Instead of trying to back up each table/database one by one into separate .sql or .zip files, I just access my web server using SSH via PUTTY and just use the following structure to dump each database into my root in .dump format:

mysqldump -h [hostname] -u [username] -p[password] [databasename] > [outputfile]

EXAMPLE:
mysqldump -hdbxxx.perfora.net -udbo1xxxxxx -pxxxxxx dbxxxxxxxx >OutputFile.dump

Later on when it is time to recover or move my database to another new Database or SQL Server, I just do the opposite using mysql instead of mysqldump:

mysql -h dbxx.perfora.net -u dboxxxxxxxx -p dbxxxxxxxx < dump_file.sql
Enter password:
mysql>

No comments:

Post a Comment