Sunday, January 11, 2015

Backup and Restore MYSQL Database

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

No comments:

Post a Comment