Back up and Restore MySQL database from the command line

Backing up via the command line:

Type the following at the prompt with the appropriate USERNAME and DATABASE name:

mysqldump -u USERNAME -p DATABASE > dump.sql

You will be prompted for your database password and then the DATABASE will be dumped to a plain-text file called dump.sql.

Restoring via the command line:

First drop and recreate the database as needed:

Drop the database

mysqladmin -u USERNAME -p drop DATABASE

Recreate the database

mysqladmin -u USERNAME -p create DATABASE

Import the backup data

mysql -u USERNAME -p DATABASE < dump.sql

3 thoughts on “Back up and Restore MySQL database from the command line

  1. Your article are really awesome. Actually I was in search for some good articles on MySQL Database Backup file and finally I got one.
    The most important thing of this article is simplicity and understandable. You’ve elaborate it very well. Check this links too it also having good explanation on MySQL database backup…..
    http://mindstick.com/Blog/239/How%20to%20Back%20Up%20and%20Restore%20a%20MySQL%20Database

    http://stackoverflow.com/questions/823841/mysql-backup-and-restore-from-command-line

    Thanks Everyone for your valuable post!

    Like

Leave a reply to amol Cancel reply