0

mySQL – How to Backup the Database

The easiest way to do this is to run mysqldump from the command line. If you have LAMP installed or manually installed mySQL on Linux, this should not be an issue. If you are running WAMP, using the command line you need to navigate to C:wampalias and keep digging through the directories until you find mySQL and its binaries.

To back up the database:

mysqldump -u root -p[password] [databasename] > backup.sql

The command is going to look wrong when you type it out, but it will not work any other way. Here’s an example using ‘topsecret’ as a password and ‘spyvault’ as the database name.

mysqldump -u root -ptopsecret spyvault > backup.sql

To go the other way with this and restore your database, use the following syntax:

mysql -u root -p[password] [databasename] < backup.sql

Same syntax, but notice the different command and direction of the ‘>’ sign.

Leave a Reply