MySQL Database Backup Using mysqldump command.
Tuesday, January 20,200 9, how-to, MySQL 195 views add a comment since its release in 1995, MySQL has became one of the most commonly used database in Internet world. A lot of small and medium businesses uses MySQL as their backend dB. its popularity for use with Web applications is closely tied to the popularity of PHP, which is often combined with MySQL. wikipedia runs on mediawiki software, which is written in PHP and uses a MySQL database. several high-traffic web sites use MySQL for its data storage and logging of user data, including Flickr, Facebook, Wikipedia, Google, Nokia and YouTube.
MySQL provide a great command line utility to take backup of your MySQL database and restore it. mysqldump command line utility is available with MySQL installation (bin directory) that can be used to achieve this.
1. Getting backup of a MySQL database using mysqldump.
Use following command line for taking backup of your MySQL database using mysqldump utility.
View plaincopy to clipboardprint?
Mysqldump -- User [user name] -- Password = [Password] [database name]> [dump file]
Or
Mysqldump-U [user name]-P [Password] [database name]> [dump file]
Mysqldump -- User [user name] -- Password = [Password] [database name]> [dump file]
Or
Mysqldump-U [user name]-P [Password] [database name]> [dump file]
Example:
View plaincopy to clipboardprint?
Mysqldump -- User Root -- Password = myrootpassword db_test> db_test. SQL
Or
Mysqldump-uroot-pmyrootpassword db_test> db_test. SQL
Mysqldump -- User Root -- Password = myrootpassword db_test> db_test. SQL
Or
Mysqldump-uroot-pmyrootpassword db_test> db_test. SQL
2. Backup Multiple databases in MySQL.
View plaincopy to clipboardprint?
Mysqldump-U [user name]-P [Password] [database name 1] [database name 2]...> [dump file]
Mysqldump-U [user name]-P [Password] [database name 1] [database name 2]...> [dump file]
Example:
View plaincopy to clipboardprint?
Mysqldump -- User Root -- Password = myrootpassword db_test db_second db_third> db_test. SQL
Mysqldump -- User Root -- Password = myrootpassword db_test db_second db_third> db_test. SQL
3. Backup all databases in MySQL.
View plaincopy to clipboardprint?
Shell> mysqldump-U [user name]-P [Password]-All-databases> [dump file]
Shell> mysqldump-U [user name]-P [Password]-All-databases> [dump file]
4. Backup a specific table in MySQL.
View plaincopy to clipboardprint?
Shell> mysqldump -- User [username] -- Password = [Password] [database name] [Table name] \
>/Tmp/sugarcrm_accounts_contacts. SQL
Shell> mysqldump -- User [username] -- Password = [Password] [database name] [Table name] \
>/Tmp/sugarcrm_accounts_contacts. SQL
Example:
View plaincopy to clipboardprint?
Shell> mysqldump -- User Root -- Password = myrootpassword db_test MERs \
> Db_test_customers. SQL
Shell> mysqldump -- User Root -- Password = myrootpassword db_test MERs \
> Db_test_customers. SQL
5. Restoring MySQL database.
The mysqldump utility is used only to take the MySQL dump. To restore the database from the dump file that you created in previous step, use MySQL command.
View plaincopy to clipboardprint?
Shell> MySQL -- U [username] -- Password = [Password] [database name] <[dump file]
Shell> MySQL -- U [username] -- Password = [Password] [database name] <[dump file]
Example:
View plaincopy to clipboardprint?
Shell> MySQL -- User Root -- Password = myrootpassword new_db <db_test. SQL
Shell> MySQL -- User Root -- Password = myrootpassword new_db <db_test. SQL
Do you know the other uses of mysqldump utility? Comment on this post.