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數據庫( )對數據庫服務器本身的使用mysqldumpMySQL事業。 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 我的數字生活論壇 .



8 Responses to “How to Backup and Restore (Export and Import) MySQL Databases Tutorial” 8回應“如何備份和恢復(出口和進口)的MySQL數據庫補習”

  1. johnrobin
    January 26th, 2008 01:32 2008年1月26日1時32分
    1

    Nice post..尼斯郵政.. I usually just copy the files..我通常只是將文件複製.. for temporary..臨時.. and get all mysql queries for permanent backup..並讓所有的MySQL查詢永久備份..

  2. ferensick
    February 4th, 2008 12:48 2008年2月4日12時48分
    2

    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) … …我試圖恢復相同的方式,但收到消息:未知數據庫:所有數據庫(我已經這樣做之前,但我忘記了,這是一個雖然… …我將繼續環顧)

  3. ferensick
    February 4th, 2008 13:17 2008年2月4日13時17分
    3

    mysql -u root -p < all-databases.sql MySQL的中美根- P的<全databases.sql
    done.做完。 :-)

  4. tc技術合作
    February 6th, 2008 03:43 2008年2月6日3時43分
    4

    mysqldump worked.工作mysqldump 。

    But ‘mysql’ to import data did not.但' MySQL的'導入數據沒有。 The error is:錯誤是:
    ERROR at line 1: Unknown command ‘\m’誤差在1號線:未知命令' \米'

    any ideas?任何想法?

  5. Mohammod Nizam Uddin mohammod尼扎姆uddin
    February 16th, 2008 02:46 2008年2月16日2時46分
    5

    thanks alot ..感謝了很多.. you saved my time and money both ..你救了我時間和金錢都.. hat off to you .小康的帽子,給您。

  6. peanut花生
    April 14th, 2008 16:31 2008年4月14日16時31分
    6

    Good post.良好的職位。 But you can add some advanced tips to it, to make it better.但您可以添加一些先進的秘訣,到它,讓它變得更加完美。 Goog luck! goog運氣!

  7. tarot塔羅牌
    May 27th, 2008 23:45 2008年5月27日23時45分
    7

    Good post, but what about backing up the mysql users them selves?良好的職位,但如何備份MySQL的用戶,他們守土有責?

  8. Importar datos de MySQL de latin1 a UTF8 « Yvoictra Blog importar datos德MySQL的德以latin1 1 utf8進行« yvoictra博客
    July 21st, 2008 07:57 2008年7月21日7時57分
    8

    [...] Enlace [...] [ … … ] enlace [ … … ]

Leave a Reply離開的答复

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> 您可以使用這些標籤:的<a href="" title=""> <abbr title=""> <acronym title="">的<b> <blockquote cite=""> <cite>的<code> <刪除日期時間= “ ” >的<em>的<i> <q cite=""> <strike>的<strong>

Subscribe without commenting訂閱無評論


Custom Search

New Articles新的條款,

Incoming Search Terms for the Article傳入的搜索條件文章

mysqldump restore mysqldump恢復 - - mysqldump import mysqldump進口 - - mysqldump utf8 mysqldump utf8進行 - - mysqldump encoding mysqldump編碼 - - mysql export database MySQL的進出口數據庫 - - mysqldump tutorial mysqldump補習 - - mysql export MySQL的出口 - - mysqldump syntax mysqldump語法 - - mysql export utf8 MySQL的出口utf8進行 - - mysql export syntax MySQL的出口語法 - - mysqldump recover mysqldump收回 - - mySQL import dump MySQL的進口轉儲 - - mysql import utf8 MySQL的進口utf8進行 - - mysql import charset MySQL的進口字符 - - mysql import backup MySQL的進口備份 - - import mysqldump 進口mysqldump - - mysql export charset MySQL的出口字符 - - phpmyadmin export encoding phpmyadmin出口編碼 - - mysqldump slow mysqldump緩慢 - - mysql import syntax MySQL的進口語法 - - phpmyadmin export utf8 phpmyadmin出口utf8進行 - - mysqldump example 例如mysqldump - - mysqldump restore windows mysqldump還原Windows - - mysql export dump MySQL的出口轉儲 - - export mysql 出口的MySQL - - phpMyAdmin export charset phpmyadmin出口字符 - - mysql import all databases MySQL的進口所有數據庫 - - mirakagi tutorial mirakagi補習 - - restore mysqldump 恢復mysqldump - - mysql export encoding MySQL的出口編碼 - - all 全部 - - phpmyadmin export tutorial phpmyadmin出口補習 - - mysql import encoding MySQL的進口編碼 - - mysql restore utf8 MySQL的恢復utf8進行 - - mysql import MySQL的進口 - - mysql import slow MySQL的進口緩慢 - - phpmyadmin export utf-8 phpmyadmin出口-8 - - export mysql database 出口MySQL數據庫 - - import mysql database 進口MySQL數據庫 - - mysql import collation MySQL的進口整理 - - mysql import database MySQL的進口資料庫 - - mysql import all-databases MySQL的全部導入數據庫 - - import mysql 進口的MySQL - - mysqldump utf-8 mysqldump -8 - - mysqldump syntax import mysqldump語法進口 - - mysqldump restore example mysqldump恢復的例子 - - mysql export table MySQL的出口表 - - mysqldump utf mysqldump的UTF - - restore data from mysqldump 還原數據從mysqldump - - import mysql backup 進口MySQL的備份 - - mysql export utf-8 MySQL的出口-8 - - mysql import database dump MySQL的進口數據庫轉儲 - - mysqldump import all databases mysqldump進口的所有數據庫 - - import mysql dump 進口MySQL的轉儲 - - mysql export innodb MySQL的出口將InnoDB - - mysql restore charset MySQL的恢復字符集 - - mysqldump import export mysqldump進出口 - - mysqldump restore data mysqldump恢復數據 - - mysqldump restore table mysqldump恢復表 - - mysql export import MySQL的進出口 - - import database dump 進口數據庫轉儲 - - mysql import character set MySQL的進口字符集 - - restore mysqldump windows 恢復mysqldump的Windows - - mysql restore MySQL的恢復 - - phpmyadmin export phpmyadmin出口 - - mysql import dump charset MySQL的進口轉儲字符 - - import mysqldump file 進口mysqldump檔案 - - mysqldump export table mysqldump導出表 - - phpmyadmin export latin1 phpmyadmin出口以latin1 - - restore mysql dump ssh 恢復MySQL的轉儲的SSH - - mysql restore all databases MySQL的恢復所有數據庫 - - mysql export tutorial MySQL的出口補習 - - phpmyadmin export character set phpmyadmin出口字符集 - - mysql import mysqldump MySQL的進口mysqldump - - mysqldump examples mysqldump的例子 - -