mysql備份與還原

來源:互聯網
上載者:User

MySQL Database Backup using mysqldump command.
Tuesday, January 20, 2009, 12:58 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 customers \  
> db_test_customers.sql 

shell> mysqldump --user root --password=myrootpassword db_test customers \
> 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.

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.