Backing up and restoring your MySQL Database

June 1, 2008 by Jason 



If you’ve been using MySQL database to store your important data, it is imperative that you make a backup of your data to prevent any loss of data. This article shows you how to backup and restore data in your MySQL database. This process can also be used if you have to move your data to a new server.

Backing up your database

The quickest and easiest way to backup and restore your database would be to use MySQLDump. If you’ve got shell or telnet access to your server, you can backup MySQL data by issuing the mysqldump command. The syntax for the command is as follows.

mysqldump -u [uname] -p [pass] [dbname] > [backupfile.sql] [uname] – this is your database username [pass]- this is the password for your database [dbname] – the name of your database [backupfile.sql] – the filename for your database backup

To backup your database ‘Customers’ with the username ’sadmin’ and password ‘pass21′ to a file custback.sql, you would issue the command

mysqldump -u sadmin -p pass21 Customers > custback.sql

Issuing this command will backup the database to custback.sql. This file can be copied to a safe location or a backup media and stored. For more information on MySQLDump, you can check out : http://www.mysql.com/doc/en/mysqldump.html

Restoring your database

If you have to re-build your database from scratch, you can easily restore the mysqldump file by issuing the following command. This method will not work if the tables already exist in your database.

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

If you need to restore existing databases, you’ll need to use MySQLImport. The syntax for mysqlimport is

mysqlimport [options] database textfile1

To restore your previously created custback.sql dump back to your Customers Database, you’d issue

mysqlimport -u sadmin -p pass21 Customers custback.sql

For more information on MySQLImport, you can check out : http://www.mysql.com/doc/en/mysqlimport.html

?

Last 5 posts in reviews

Comments

BEST OF VBULLETINSETUP
Thumbnail Merging a vBulletin forum to vBulletinSetup

Do you have experience merging databases with vBulletin? I’ve... 

Thumbnail vBulletinSetup Contest Free Styles, Hacks and more vBulletin Skins

We are about one third of the way through our latest vBulletinSetup... 

Thumbnail vBulletin Setup Contest for vBulletin Styles & Hacks

It’s contest time again here at vBulletin Setup! We are... 

Thumbnail Download the vBSEO 3.3.0 RC1 Release

Full compatibility with vBulletin 3.8.x. This is our first release... 

Thumbnail Submit your RSS feeds to over 58 search engines and top directories

Submit your Blogs and Forums RSS feeds to over 58 search engines... 

Thumbnail Sponsor our Next Contest!

We’ve had some very successful contest in the vBulletinSetup... 

Thumbnail vBulletin host, The best vBulletin host

Hosting your vBulletin forum can be a difficult decision if... 

Looking for something?

Search our community forums:


crowdgather  A member of the Crowdgather Forum Community
Powered by WordPress      |       Legal

Visit our other communities

A few highly recommended forums...

Archives

All entries, chronologically...