Quick MySql backup/restore tutorial
Posted: Tue Mar 27, 2012 6:51 am
Code: Select all
mysqldump -u [Username] -p [password] [databasename] > [backupfile.sql]
[password]- this is the password for your database
[databasename] - the name of your database
[backupfile.sql] - the filename for your database backup
Let's discuss the example of backing up MySQL Database named "accounts" into text file accounts.sql. Here are the scenarios of taking the backup assuming that both user name and password of the database is "admin".
- Taking the full backup of all the tables including the data. Use the following command to accomplish this:
Code: Select all
mysqldump -u admin -p admin accounts > accounts.sql
- Taking the backup of table structures only. Use the following command to accomplish this:
Code: Select all
mysqldump -u admin -p admin --no-data accounts > accounts.sql
- Taking the backup data only. Use the following command to accomplish this:
Code: Select all
mysqldump -u admin -p admin --no-create-info accounts > accounts.sql
Restoring the MySQL is very easy job. You can use the following to command to restore the accounts database from accounts.sql backup file.
Code: Select all
mysql - u admin -p admin accounts < accounts.sql