Home > General > How to Backup and Restore a MySQL Database

How to Backup and Restore a MySQL Database

To make a database backup using the MySQL command-line utilities, execute the following command:

$ mysqldump -u username -p –opt dbname > dump.sql

It will ask you for password because we used -p paramater over there. If the MySQL programs are not in your path, you will need to manually specify the location of the mysqldump program:

$ /path-to-your-mysql-bin/mysqldump -u username -p –opt dbname > dump.sql

Download the dump.sql and keep it in a safe place (CDR, Zip disk, etc).

If you need to restore your database, you can do so like this:

$ mysql -u username -p dbname < dump.sql

This is the simples way to restore and backup your database.

VN:F [1.9.22_1171]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)
Categories: General Tags: ,
  1. JamesD
    June 11th, 2009 at 20:34 | #1

    Thanks for the useful info. It’s so interesting

    VA:F [1.9.22_1171]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.22_1171]
    Rating: 0 (from 0 votes)
  1. No trackbacks yet.