How to restore and backup mysql databases?

I forget the commands everytime I backup/restore mysql databases. For this reason I am writing them down for my reference and hopefully others will also find them useful.

Suppose my database credentials are as follow:

db username:  vijay
db password:  somepwd
database:     catalogue

Taking backup of database

Go to the command line (not mysql command line) and fire the following command:

mysqldump -u username -p password database > dump.sql

After replacing with original values this becomes:

mysqldump -u vijay -p somwpwd catalogue > dump.sql

This command will generate a sql file named dump.sql.

Restore the database

Now you would like to restore the above created dump.sql to some other server. Here is the command

mysql -u username -p password database < dump.sql

This becomes:

mysql -u vijay -p somepwd catalogue < dump.sql

This will restore the data from dump.sql file to catalogue database.

Most Commented Posts

Technology

If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.

Leave Comment

(required)

(required)


9,433 spam comments
blocked by
Akismet