程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> MYSQL數據庫 >> 關於MYSQL數據庫 >> DB2 與 MySQL 數據轉移

DB2 與 MySQL 數據轉移

編輯:關於MYSQL數據庫
如果您是一位要同時管理 MySQL 和 IBM® DB2® Express-C 的 DBA,就需要理解這兩種數據庫服務器的功能差異。本文是系列文章中的第 4 篇,這個系列幫助具有 MySQL 背景的 DBA 學習如何管理 DB2 Express。在本文中,學習在這兩種產品中數據轉移技術有何差異。討論的技術包括 Import、Export、Load 以及專門用於數據轉移的其他實用程序。

  簡介和背景知識

  在 2006 年 7 月 28 日,IBM 發布了下一個 DB2 for Linux®, UNIX®, and Windows® 版本,這是一種為滿足當今復雜的業務需求而設計的混合型數據服務器。這個版本提供了第一個支持本機 XML 存儲的工業強度的數據服務器。壓縮、安全和自治功能等其他特性也得到了改進。

  在 developerWorks DB2 for Linux, UNIX, and Windows 信息管理參考資料頁面 上可以找到對 DB2 Express-C 9 支持的特性的概述和深入討論。這些特性包括 PureXML™,這個特性確保企業能夠以本機方式利用 XML 功能。有了 DB2 Express-C 9 PureXML 特性,就不再需要將文檔存儲在大對象(LOB)中或者將它們分解成對象。盡管 IBM DB2 Express-C 非常適合中小型企業的需求,但是它沒有提供更高版本中的所有可用特性。DB2 Express-C 不包含其他 DB2 9 版本中的以下特性:

  ·Replication(但是支持 Homogeneous Replication)

  ·數據庫分區特性

  ·Connection Concentrator

  ·DB2 Geodetic Extender

  ·Query Patroller

  ·Net Search Extender

  ·Compression

  ·Label Base Access Control - LBAC

  另外,要記住 IBM DB2 Express-C 9 是 “免費開發”、“免費部署” 和 “免費發布” 的。

  從 DB2 Express-C 8 到 DB2 Express-C 9,有許多改進,這些改進超出了本文的范圍。但是,數據轉移的特性和功能大體上保持不變。本文概述 IBM DB2 Express-C 9.1 的數據轉移特性。本文主要關注它們的功能,同時提及 MySQL 的數據轉移功能。如果您熟悉 MySQL 的數據轉移,那麼可以跳過 “MySQL 數據轉移” 一節,直接學習 IBM DB2 Express-C 9.1 的數據轉移。

  討論的主題 - 概述

  本文首先介紹 MySQL 中的數據轉移。接下來,本文討論 IBM DB2 Express-C 的數據轉移,這可以分為以下主題。

  ·導入 - Import 實用程序和 DB2 Load

  ·導出 - Export 實用程序

  ·其他可用工具

  MySQL 數據轉移

  MySQL 提供的用於數據轉移的實用程序主要有兩個。它們是 mysqldump 和 mysqlhotcopy。盡管這兩個實用程序主要用來進行備份和恢復,但是它們可以用來建立現有表或整個數據庫的拷貝,因此能夠將數據從一個數據庫(常常是中小規模的數據庫)轉移到同一服務器或其他服務器中的另一個數據庫中。選擇 mysqldump 還是 MySQLhotcopy 取決於要復制的數據庫的規模、設置的成本、鎖機制、恢復選項、表的類型等等。表 1 對比了 MySQL 提供的這兩個實用程序。

  盡管有許多建立數據庫或部分數據庫的拷貝的方法,比如操作系統級復制、select ... into outfile、mysqlsnapshot以及 InnoDB 的熱備份,但是本文只關注 mysqldump 和 MySQLhotcopy。各種方法之間的比較及其優缺點超出了本文的范圍。

  例如,對於 MySQLdump,要想建立整個數據庫的拷貝,最常見的方法可能是發出以下命令:

  清單 1. 使用 MySQLdump 創建完整的數據庫拷貝

MySQLdump --opt db_name > backup-file.sql

  導入它的方法是發出以下命令:

  清單 2. 使用 MySQLdump 導入完整的數據庫

MySQL db_name < backup-file.sql

  清單 3 中列出了 mysqldump 支持的一些重要標志。發出 MySQLdump -? 命令可以獲得完整的列表。

  清單 3. MySQLdump 選項

 -A, --all-databases Dump all the databases. This will be same as --databases
           with all databases selected.
 --add-drop-database Add a 'DROP DATABASE' before each create.
 --add-drop-table  Add a 'drop table' before each create.
 --add-locks     Add locks around insert statements.
 --allow-keywords  Allow creation of column names that are keyWords.
 --character-sets-dir=name
           Directory where character sets are.
 -c, --complete-insert
           Use complete insert statements.
 -C, --compress   Use compression in server/clIEnt protocol.
 --create-options  Include all MySQL specific create options.
 -B, --databases   To dump several databases. Note the difference in usage;
           In this case no tables are given. All name arguments are
           regarded as databasenames. 'USE db_name;' will be
           included in the output.
           Set the default character set.
 --delayed-insert  Insert rows with INSERT DELAYED;
 --delete-master-logs
           Delete logs on master after backup. This automatically
           enables --master-data.
 -e, --extended-insert
           Allows utilization of the new, much faster INSERT syntax.
 --fIElds-terminated-by=name
           FIElds in the textfile are terminated by ...
 --fIElds-enclosed-by=name
           FIElds in the importfile are enclosed by ...
 --fIElds-optionally-enclosed-by=name
           FIElds in the i.file are opt. enclosed by ...
 --fIElds-escaped-by=name
           FIElds in the i.file are escaped by ...
 --order-by-primary Sorts each table's rows by primary key, or first unique
           key, if such a key exists. Useful when dumping a MyISAM
           table to be loaded into an InnoDB table, but will make
           the dump itself take considerably longer.
 --single-transaction
           Creates a consistent snapshot by dumping all tables in a
           single transaction. Works ONLY for tables stored in
           storage engines which support multiversioning (currently
           only InnoDB does); the dump is NOT guaranteed to be
           consistent for other storage engines. Option
           automatically turns off --lock-tables.
  -T, --tab=name   Creates tab separated textfile for each table to given
           path. (creates .sql and .txt files). NOTE: This only
           works if MySQLdump is run on the same Machine as the
           MySQLd daemon.
  --tables      Overrides option --databases (-B).
  --triggers     Dump triggers for each dumped table
  -X, --xml      Dump a database as well formed XML.

  盡管 mysqldump 適合對中小規模的表和數據庫進行備份,但是 mysqlhotcopy 的能力更強。不過要注意,mysqlhotcopy 不具有 MySQLdump 那麼大的靈活性。要記住一點,它只能在數據庫目錄所在的機器上運行。

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved