Thursday, February 17, 2011

Backup and Restore Mysql database

It is very important to backup databases to prevent any loss of data. The easiest way backup the database is Mysqldump and we can restore it with mysql command...

Backup Syntax:
#mysqldump -u [username] -p [databasename] > dumpfilename.sql

Ex: assume that you want to backup a database called users and with username root, then the command would be....
#mysqldump -u root -p users > users.sql
In the above example "-p" will prompt for password, and if your mysql doesnot have any password then no need to use "-p".

Restore Syntax:
Mysqldump file can easily be restored by using the following command
#mysql -u root -p [databasename] < [mysqldumpfile.sql]

EX: #mysql -u root -p users < users.sql

No comments:

Post a Comment