System News
   
News about Solaris and Sun Microsystems

Free 2 Week Trial!


June 16, 2008
Article #20135
Volume 124, Issue 3
Section: Developer

 

several approaches to backing up and restoring a MySQL Database
 


 

A Couple of Simple Approaches to Backing Up and Restoring a MySQL Database
Also Useful for Moving Data to New Web Servers

There are several approaches to backing up and restoring a MySQL Database, and a few techniques are presented in an entry from the Online Diary blog with the commands necessary to accomplish each. The author notes that these procedures are also useful for moving data to new web servers.

The tutorial teaches the following:

  • Back up From the Command Line (using mysqldump)
  • Back up your MySQL Database with Compress
  • Restoring your MySQL Database
  • Backing Up and Restoring using PHPMyAdmin

Back up From the Command Line (using mysqldump)

In addition to providing the step-by-step procedure for this back up, the blog also notes several other useful options available using the mysqldump command:

  • add-drop-table: Tells MySQL to add a DROP TABLE statement before each CREATE TABLE in the dump.
  • no-data: Dumps only the database structure, not the contents.
  • add-locks: Adds the LOCK TABLES and UNLOCK TABLES statements you can see in the dump file.

Back up your MySQL Database with Compress

Users with large databases can compress the output of mysqldump, turning it into a gzip file. Commands for this and for extracting the .gz file are provided.

Restoring your MySQL Database

Recreating the Tutorials database involves two steps:

  • Create an appropriately named database on the target machine
  • Load the file using the mysql command

The blog provides instructions for restoring the tut_backup.sql file to the tutorials database; for restoring compressed backup files; and for restoring a database that already exists.

Backing Up and Restoring using PHPMyAdmin

Only a few steps are necessary for this backup and restore with PHPMyAdmin:

  • Open phpMyAdmin.
  • Select your database by clicking the database name in the list on the left of the screen.
  • Click the Export link. This should bring up a new screen that says View dump of database (or something similar).
  • In the Export area, click the Select All link to choose all of the tables in your database.
  • In the SQL options area, click the right options.
  • Click on the Save as file option and the corresponding compression option and then click the ‘Go’ button. A dialog box should appear prompting you to save the file locally.

Restoring the database is equally simple:

  • Open phpMyAdmin.
  • Create an appropriately named database and select it by clicking the database name in the list on the left of the screen. If you would like to rewrite the backup over an existing database then click on the database name, select all the check boxes next to the table names and select Drop to delete all existing tables in the database.
  • Click the SQL link. This should bring up a new screen where you can either type in SQL commands, or upload your SQL file.
  • Use the browse button to find the database file.
  • Click Go button. This will upload the backup, execute the SQL commands and re-create your database.

For more, see http:webcheatsheet.com. [...read more...]

Keywords:
Other articles in the Developer section of Volume 124, Issue 3:

See all archived articles in the Developer section.


From the latest issue:



 


Customized news reports about Sun Microsystems. Just the news you need, none of what you don't.
50,000+ Members. 20,000+ Articles Published since 1998.