| Home ->
Mysql -> Backup
& Restore |
|
|
| |
| |
| A Simple Database Backup |
You can use mysqldump to create a simple backup of your
database using the following syntax.
mysqldump -u [username] -p [password] [databasename] >
[backupfile.sql]
o [username] - this is your database username
o [password] - this is the password for your database
o [databasename] - the name of your database
o [backupfile.sql] - the file to which the backup should
be written.
The output dump file will contain all the SQL statements
needed to create the table in a database. The file can
also be ftp over to a another server for creating the
database and table for disater recovery purpose.
Below is an example to backup the database called employee
mysqldump -u mysql -p password employee> emp.sql |
| |
| How to restore mysql database |
Here's how you would restore your database from a .sql
backup file
mysql -u [username] -p [password] [database_to_restore]
< [backupfile]
example : Here's how you would restore your emp.sql file
to the employee database. Easy isn't it ?
mysql -u mysql -p password employee < emp.sql |
| |
| Restoring mysql database without
username and passwd as root |
syntax : mysql [database_to_restore] < [backupfile]
example: root@srvr # mysql database_name < database_backfile.sql
Note :Make sure the database is already existing or created
before restoring |
| |
| Backing up only specified tables |
If you need to make a backup of certain tables in your
database that is possible by only specifying the tables
with the correct syntax. For example : you want to only
backup 2 tables called employee_dept and employee_data
of a database called employee, you can run the below mysql
commad at command line:
mysqldump --add-drop-table -u mysql-p password employee
employee_dept employee_data > empl_tables.sql
So the syntax for the command to issue is:
mysqldump -u [username] -p [password] [databasename] [table1-list2
]
[tables-list] - This is a list of tables to backup. Each
table is separated by a space. |
| |
| |