I know many of you out there have asked yourself the question “how do I backup my website’s database?” Well I have the one line of code that will rock your world. This method assumes that you have SSH access(You will need to check with your hosting provider for setup).
Step one, obtain your database credentials. Typically, you can find these in your hosting accounts control panel or WordPress config file.
Step two, establish a ssh connection to your hosting account.
Step three, execute the following command:
mysqldump -u[username] -p[password] –host=[dbserver] –all-databases | gzip > ~/database_`date +%m-%d-%Y-%H%M`.sql.gz
Once the backup is done, you can ftp the file from your server for a rainy day. Personally, I just leave them on the server, they are picked up when I do an account backup. As you can see this method makes it very easy to make a full database backup in minimal time. I like it because I don’t need to spend time logging into my accounts control panel and browsing through menus. I just find SSH much easier.
Keep in mind you could use this command many ways. You could place it in a cron or implement it via the PHP exec function. Leave a comment and let me know, how do you plan on using the command.