SEARCH

How-To Geek

Backup MySQL Database to a file

Backing up your database is a very important system administration task, and should generally be run from a cron job at scheduled intervals. We will use the mysqldump utility included with mysql to dump the contents of the database to a text file that can be easily re-imported.

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 09/11/06

Comments (3)

  1. hun

    Very useful. Thanks

  2. dragonbite

    Good timing. I’m doing development on an ASP.NET website in both Windows and multiple Linux machines (via Mono) and I need to easily dump an updated backup file into the same shared folder (all via Dropbox) so whatever system I am developing on I can update the database.

  3. Superman

    Hi there was just wondering, do you use mysql commandline or could you use command prompt to execute the syntax

    I tried command prompt and it said access denied, LOCK TABLES?
    Could you help?
    thanx

Enter Your Email Here to Get Access for Free:

Go check your email!