Quick MySql backup/restore tutorial

Post Reply
User avatar
Saman
Lieutenant Colonel
Lieutenant Colonel
Posts: 828
Joined: Fri Jul 31, 2009 10:32 pm
Location: Mount Lavinia

Quick MySql backup/restore tutorial

Post by Saman » Tue Mar 27, 2012 6:51 am

Code: Select all

mysqldump -u [Username] -p [password] [databasename] > [backupfile.sql]
[username] - this is your database username
[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".
  1. 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
  2. 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
  3. 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
Post Reply

Return to “PHP & MySQL”