How To Backup And Restore A MySQL Database Through Command LineFebruary 1st, 2008 · 1 Comment
Using MySQL Command LineWhether you are using MySQL on Linux or MS Windows, you can use the command line to perform most tasks. If you are using MS Windows, make the path to the command line binaries is included in your system path. This will make things easier for you otherwise you’ll have to type the full path to each command. How To Backup A MySQL DatabaseMySQL provides a utility called “mysqldump”. Basically what this tool does it it creates a flat file containing the SQL instructions to restore your database. Here are a few usage examples of mysqldump: Creating a simple database backup
This will create a file containing all the SQL statements to create tables and restore data into an existing database. If the target database contains tables with the same names, they will be overwritten. If you want the existing tables to be dropped and recreated, use the add-drop-table option:
You could also choose to drop the whole database before recreating it and restoring data:
Backing Up Multiple Databases You can backup multiple databases to a single file using the databases option:
Creating a backup of all databases can be achieved using the all-databases option:
Backing Up InnoDB Tables If you database has InnoDB tables, you will need to deactivate referential integrity while restoring data. Unfortunately, this can’t be done using the mysqldump utility. To do so, backup your database as you would normally. When done, open the SQL file and add the following statement at the very beginning:
…and add the following at the end of the file:
Compressing MySQL Dump FileIf you are using mysqldump in a Linux shell, you can pipe it through gzip to compress the dump file (assuming you have gzip installed):
Restoring A MySQL BackupTo restore a backup created with mysqldump, you will need to use the mysql command. If your SQL dump file does not contain any “create database” statement, you can use the following command:
But if it does, simply use the same command without specifying the database name:
More information on mysqldump can be found here. Related PostsPosted in Tutorials | 1 Comment |
Popular Posts
Latest Posts
Latest Deals & CouponsRecent Comments
Hosting ReviewsRecent WebmastersTag Cloud
1and1
apache
bluehost
centos
cheap web hosting
control panel
coupon
coupon code
cpanel
dedicated servers
dreamhost
godaddy
green web hosting
hostdime
hostgator
hostpapa
iis
inmotion hosting
knownhost
linux
lunarpages
mysql
openx
php
reseller hosting
shared hosting
system administration
vps
web hosting
web hosting comparison
Web Hosting Comparisons
whm
windows
windows 2008
wordpress
|
|||||||||
1 response so far ↓
1. Response by : What’s In Your cPanel Backup? on Oct 9, 2008 at 12:03 am
[...] If the file is still too large, you have only two options left: ask your hosting provider to restore the file for you or if you have SSH access, restore the database from a command line. [...]
Leave a Comment