SEARCH

How-To Geek

Backup Your MySQL Server from the Command Line

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…

Syntax:

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

Example:

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

Get Free Articles in Your Inbox!

Join 134,000 newsletter readers

Email:

Go check your email!