Data base backup


Mysql Database Backup

Rule 1 You should always backup your database


Rule 2 You should backup your database regularly, and always before an upgrade


Rule 3 If you don't backup your database, eventually something will happen, you will lose all your data and you will wish you had backed up your database

 

Now for the good news, If you use Database Backup Generator, you can sit back safe in the knowledge that your database is being backed up, and its child's play to restore a corrupt database.

More information on the hard way to backup your mysql database

Article Index
1.
Backing up and Restoring your MySQL Database  
2. What about Multiple Databases  
3. Easy Restore  
4. PHPMy Admin  
5. Backing up and Restoring your databse with PHPMy Admin  
6. Home  
     

(Page 3 of 5 )

Backing Up and Restoring Your MySQL Database - Easy Restore

Now that you've got backups of your database, let's learn how to restore your backup in case your database goes down. Here's how you can restore your backed up database using the mysql command.

Restore using mysql

If you have to re-build your database from scratch, you can easily restore the mysqldump file by using the mysql command. This method is usually used to recreate or rebuild the database from scratch.

Here's how you would restore your custback.sql file to the Customers database.

mysql -u sadmin -p pass21 Customers < custback.sql

Easy isn't it ? Here's the general format you would follow:

mysql -u [username] -p [password] [database_to_restore] < [backupfile]

Now how about those zipped files? You can restore your zipped backup files by first uncompressing its contents and then sending it to mysql.

gunzip < custback.sql.sql.gz | mysql -u sadmin -p pass21 Customers

You can also combine two or more backup files to restore at the same time, using the cat command. Here's how you can do that.

cat backup1.sql backup.sql | mysql -u sadmin -p pass21

Moving Data Directly Between Databases

How would you like to replicate your present database to a new location? When you are shifting web hosts or database servers , you can directly copy data to the new database without having to create a database backup on your machine and restoring the same on the new server . mysql allows you to connect to a remote database server to run sql commands. Using this feature, we can pipe the output from mysqldump and ask mysql to connect to the remote database server to populate the new database. Let's say we want to recreate the Customers database on a new database server located at 202.32.12.32, we can run the following set of commands to replicate the present database at the new server.

mysqldump -u sadmin -p pass21 Customers | mysql --host=202.32.12.32 -C Customers