Backup Your MySQL Server from the Command Line

By Lowell Heddings on December 17th, 2009

It’s very important to keep your database server backed up, and Linux makes this a trivial task from the command line. You should really put this into a cron job and run it daily (or more often), but for our purposes today, this is how to actually do the backup.

The mysqldump utility creates a complete copy of the database in text format with INSERT statements and CREATE TABLE, etc. In fact, it wouldn’t take much work to restore the database onto a completely different database platform.

Anyway, here we go…


mysqldump -h localhost -u root -pmypassword databasename > dumpfile.sql


mysqldump -h localhost -u root -p2Uad7as9 database01 > dumpfile.sql

This will give you a text file containing all the commands required to recreate the database.

Lowell Heddings, better known online as the How-To Geek, spends all his free time bringing you fresh geekery on a daily basis. You can follow him on if you'd like.

  • Published 12/17/09
More Articles You Might Like

Enter Your Email Here to Get Access for Free:

Go check your email!