How to Backup and Restore (Export and Import) MySQL Databases Tutorial如何備份和恢復(出口和進口)的MySQL數據庫補習
phpMyAdmin can be used to export or backup MySQL databases easily. phpmyadmin可以用來出口或備份的MySQL數據庫容易。 However, if the database size is very big, it probably won’t be a good idea.不過,如果數據庫大小是非常大的,它可能不會是一個好主意。 phpMyAdmin allows users to save database dump as file or display on screen, which involves exporting SQL statements from the server, and transmitting the data across slower network connection or Internet to user’s computer. phpmyadmin允許用戶保存數據庫轉儲文件或顯示在屏幕上,其中涉及出口的SQL語句,從服務器,並轉遞數據慢,網絡連接或互聯網用戶的計算機上。 This process slow the exporting process, increase database locking time and thus MySQL unavailability, slow the server and may simply crash the Apache HTTPD server if too many incoming web connections hogging the system’s resources.這個過程緩慢,出口過程中,增加數據庫鎖定時間,從而MySQL的欠缺,緩慢服務器和可能只是墜毀的Apache的httpd服務器如果有太多傳入的Web連接荒加工系統的資源。
The better way to backup and export MySQL database is by doing the task locally on the server, so that the tables’ data can be instantly dumped on the local disk without delay.該更好的方式來備份和出口MySQL數據庫是這樣做的任務,本地的服務器上,因此該表的數據可以即時棄置於本地磁盤,以免延誤。 Thus export speed will be faster and reduce the time MySQL database or table is locked for accessing.因此,出口速度將更快的時間縮短MySQL數據庫或表鎖定訪問。 This tutorial is the guide on how to backup (export) and restore (import) MySQL database(s) on the database server itself by using the mysqldump and mysql utilities.本教程是指導就如何備份(出口)和恢復(進口) MySQL數據庫( )對數據庫服務器本身的使用mysqldump與MySQL事業。 There are basically two methods to backup MySQL, one is by copying all table files (*.frm, *.MYD, and *.MYI files) or by using mysqlhotcopy utility, but it only works for MyISAM tables.有基本上是兩種方法來備份MySQL的,一個是由複製所有表文件( *. frm , *. myd , *. myi文件) ,或使用mysqlhotcopy實用工具,但它僅適用於myisam表。 Below tutorial will concentrate on mysqldump which works for both MyISAM and InnoDB tables.下面的教程將集中在mysqldump ,其中工程都myisam和InnoDB表。
How to Export or Backup or Dump A MySQL Database 如何導出或備份或轉儲一個MySQL數據庫
To export a MySQL database into a dump file, simply type the following command syntax in the shell.出口MySQL數據庫成為一個轉儲文件,只需鍵入以下命令語法在蜆殼公司。 You can use Telnet or SSH to remotely login to the machine if you don’t have access to the physical box.您可以使用Telnet或SSH遠程登錄到機器如果您還沒有接觸到身體中。
mysqldump -u username -p password database_name > dump.sql mysqldump中美用戶名 - 密碼database_name > dump.sql
Replace username with a valid MySQL user ID, password with the valid password for the user (IMPORTANT: no space after -p and the password, else mysqldump will prompt you for password yet will treat the password as database name, so the backup will fail) and database_name with the actual name of the database you want to export.取代使用者名稱與一個有效的MySQL用戶ID , 密碼與有效的用戶的密碼(重要:沒有空間後- P和密碼,否則, mysqldump會提示您密碼,但對待的密碼資料庫名稱,因此,備份將失敗)和database_name與實際資料庫的名稱,您要匯出。 Finally, you can put whatever name you like for the output SQL dump file, here been dump.sql .最後,您可以放置任何您喜歡的名稱為輸出的SQL轉儲文件,在這裡被dump.sql 。
The while data, tables, structures and database of database_name will be backed up into a SQL text file named dump.sql with the above command.同時,資料,統計表,結構和數據庫database_name將備份到一個SQL的文本文件,命名為dump.sql與上述命令。
How to Export A MySQL Database Structures Only 如何導出一個MySQL數據庫結構,只有
If you no longer need the data inside the database’s tables (unlikely), simply add –no-data switch to export only the tables’ structures.如果您不再需要的數據,數據庫內的表(不大可能) ,只需添加-沒有數據切換到出口只表'的結構。 For example, the syntax is:舉例來說,語法是:
mysqldump -u username -p password –no-data database_name > dump.sql mysqldump中美用戶名 - 密碼 -無數據database_name > dump.sql
How to Backup Only Data of a MySQL Database 如何備份數據只有一個MySQL數據庫
If you only want the data to be backed up, use –no-create-info option.如果您只想要的數據備份, 使用沒有創建-信息選項。 With this setting, the dump will not re-create the database, tables, fields, and other structures when importing.與此設置,轉儲將不會重新建立數據庫,表,字段,及其他構築物,當進口。 Use this only if you pretty sure that you have a duplicate databases with same structure, where you only need to refresh the data.使用這只是如果您相當肯定您有重複的數據庫具有相同的結構,在這裡您只需要刷新數據。
mysqldump -u username -p password –no-create-info database_name > dump.sql mysqldump中美用戶名 - 密碼 -沒有創建-信息database_name > dump.sql
How to Dump Several MySQL Databases into Text File 如何轉儲幾個MySQL的數據庫到文本文件
–databases option allows you to specify more than 1 database. -數據庫選項可讓您指定多於1數據庫。 Example syntax:例如語法:
mysqldump -u username -p password –databases db_name1 [db_name2 ...] > dump.sql mysqldump中美用戶名 - 密碼 -數據庫db_name1 [ db_name2 ... ] > dump.sql
How to Dump All Databases in MySQL Server 如何轉儲所有數據庫在MySQL服務器
To dump all databases, use the –all-databases option, and no databases’ name need to be specified anymore.傾倒的所有數據庫,使用所有數據庫選項,並沒有數據庫的名稱必須指明了。
mysqldump -u username -p password –all-databases > dump.sql mysqldump中美用戶名 - 密碼 -所有-數據庫> dump.sql
How to Online Backup InnoDB Tables 如何聯機備份InnoDB表
Backup the database inevitable cause MySQL server unavailable to applications because when exporting, all tables acquired a global read lock using FLUSH TABLES WITH READ LOCK at the beginning of the dump until finish.備份數據庫的必然原因MySQL服務器無法申請,因為當出口國,所有表格,獲得了全球讀鎖使用沖水表讀鎖定在開始轉儲,直到完成。 So although READ statements can proceed, all INSERT, UPDATE and DELETE statements will have to queue due to locked tables, as if MySQL is down or stalled.所以,雖然讀報表可以進行,所有的INSERT , UPDATE和DELETE語句將有排隊,由於鎖定表,如果MySQL的下降或停滯不前。 If you’re using InnoDB, –single-transaction is the way to minimize this locking time duration to almost non-existent as if performing an online backup.如果您使用的InnoDB軟件, 單交易的方式,以盡量減少鎖定時間,這時間,以幾乎不存在,因為如果執行聯機備份。 It works by reading the binary log coordinates as soon as the lock has been acquired, and lock is then immediately released.它的工作原理讀二進制日誌坐標盡快鎖定已獲得的,並鎖定,然後立即釋放。
Syntax:語法:
mysqldump -u username -p password –all-databases –single-transaction > dump.sql mysqldump中美用戶名 - 密碼 -所有-數據庫-單交易> dump.sql
How to Restore and Import MySQL Database 如何恢復和進口MySQL數據庫
You can restore from phpMyAdmin, using Import tab.您可以恢復從phpmyadmin ,使用進口標籤。 For faster way, upload the dump file to the MySQL server, and use the following command to import the databases back into the MySQL server.為更快的方式,上傳轉儲文件,以MySQL服務器,並使用下列命令導入數據庫回复到MySQL服務器。
mysql -u username -p password database_name < dump.sql MySQL的中美用戶名 - 密碼database_name < dump.sql
The import and export of MySQL database not only is important to recover the data when disaster strikes, but also provides an easy way to migrate or move to another server, such as when switching web hosting providers.進口和出口MySQL數據庫不僅是重要的是要恢復數據災難時的罷工,但也提供一個簡單的方式遷移或移動到另一台服務器,如切換時的Web託管服務提供商。 However, do note that one common problem - character set encoding.然而,請注意,一個共同的問題-字符集編碼。 Newer release of mysqldump uses UTF8 as its default charset if nothing is specified, while older versions (older than 4.1 typically) use Latin1 as default characterset.較新版本的mysqldump使用utf8進行其默認的字符集,如果沒有指定,而舊版本(年紀比4.1通常)使用以latin1作為默認的字符集。 If you database charset is Latin1 and dump in UTF8 collation, the data may ends up become simply rubbish, garbled, or unreadable (frequently happen with Wordpress blog).如果您的數據庫字符集是拉丁文和轉儲在utf8進行整理,該數據可能最終成為純粹的垃圾,亂碼,或無法讀取(經常發生的WordPress所博客) 。 If this case, use –default-character-set=charset_name option to specify the character set or如果這種情況下,使用默認的字符集= charset_name選項來指定字符集或 convert the database to UTF8轉換數據庫,以utf8進行 . 。
IMPORTANT : This is a machine translated page which is provided "as is" without warranty. 重要說明 :這是一個機器翻譯網頁是“按原樣”提供的擔保。 Machine translation may be difficult to understand.機器翻譯可能很難理解。 Please refer to請參閱 original English article英文原版的文章 whenever possible.只要有可能。
Share and contribute or get technical support and help at分享和貢獻,或取得技術的支持和幫助,在 My Digital Life Forums 我的數字生活論壇 . 。
Related Articles相關文章
- Restore Full Backup or cpmove File in cPanel Web Host恢復完整備份或cpmove文件中的cPanel Web主機
- How to Export Firefox Bookmarks to IE Internet Explorer Favorites (or Import From)如何導出Firefox書籤IE瀏覽器Internet Explorer收藏夾(或進口)
- IMP-00013 Oracle Import Error進出口- 00013甲骨文進口錯誤
- IMP-00016 Required Character Set Conversion Not Supported Error when Import to Oracle Database進出口- 00016所需的字符集轉換不支持時出現錯誤,導入到Oracle數據庫
- Check and Optimize MySQL Database Automatically with Crontab/Cron檢查和優化MySQL數據庫自動與crontab /玉米
- MySQL Database Performance Tuning Best Practices Video Tutorial MySQL數據庫性能調整的最佳做法視頻教程
- Export, Backup or Copy Out the IE7 Search Providers List出口,備份或複製出的IE7搜索服務提供商名單
- Backup an iTunes Playlist備份iTunes播放列表
- Oracle EXP-00091 Error When Export Database甲骨文進出口- 00091時發生錯誤,進出口數據庫
- Firefox Passwords Exporter and Importer (also for Thunderbird, Songbird and Flock) Firefox的密碼,出口商和進口商的(也為雷鳥,鳴禽和羊群)



















January 26th, 2008 01:32 2008年1月26日1時32分
Nice post..尼斯郵政.. I usually just copy the files..我通常只是將文件複製.. for temporary..臨時.. and get all mysql queries for permanent backup..並讓所有的MySQL查詢永久備份..
February 4th, 2008 12:48 2008年2月4日12時48分
It shows how to backup all-databases… but how to restore all of them at once from the same file?它顯示了如何備份所有數據庫… …但如何還原他們都在一次由相同的檔案? … I tried restoring the same way but receive a msg: unknown database: all-databases (I’ve done it before but I forget, it’s been a while… I’ll keep looking around) … …我試圖恢復相同的方式,但收到消息:未知數據庫:所有數據庫(我已經這樣做之前,但我忘記了,這是一個雖然… …我將繼續環顧)
February 4th, 2008 13:17 2008年2月4日13時17分
mysql -u root -p < all-databases.sql MySQL的中美根- P的<全databases.sql
done.做完。
February 6th, 2008 03:43 2008年2月6日3時43分
mysqldump worked.工作mysqldump 。
But ‘mysql’ to import data did not.但' MySQL的'導入數據沒有。 The error is:錯誤是:
ERROR at line 1: Unknown command ‘\m’誤差在1號線:未知命令' \米'
any ideas?任何想法?
February 16th, 2008 02:46 2008年2月16日2時46分
thanks alot ..感謝了很多.. you saved my time and money both ..你救了我時間和金錢都.. hat off to you .小康的帽子,給您。
April 14th, 2008 16:31 2008年4月14日16時31分
Good post.良好的職位。 But you can add some advanced tips to it, to make it better.但您可以添加一些先進的秘訣,到它,讓它變得更加完美。 Goog luck! goog運氣!
May 27th, 2008 23:45 2008年5月27日23時45分
Good post, but what about backing up the mysql users them selves?良好的職位,但如何備份MySQL的用戶,他們守土有責?
July 21st, 2008 07:57 2008年7月21日7時57分
[...] Enlace [...] [ … … ] enlace [ … … ]