使用 Azure Data Factory 或 Synapse Analytics 從 MariaDB 複製數據

適用於:Azure Data Factory Azure Synapse Analytics

提示

試用 Microsoft Fabric 中的 Data Factory,這是適用於企業的全方位分析解決方案。 Microsoft Fabric 涵蓋從資料移動到資料科學、即時分析、商業智慧和報告的所有項目。 了解如何免費啟動新的試用版

本文概述如何使用 Azure Data Factory 或 Synapse Analytics 管線中的複製活動,從 MariaDB 複製數據。 本文是根據複製活動概觀一文,該文提供複製活動的一般概觀。

支援的功能

下列功能支援此 MariaDB 連接器:

支援的功能 IR
複製活動 (來源/-) (1) (2)
查閱活動 (1) (2)

① Azure 整合執行階段 ② 自我裝載整合執行階段

如需複製活動所支援作為來源/接收器的資料存放區清單,請參閱支援的資料存放區表格。

此服務提供的內建驅動程式可啟用連線,因此,您不需手動安裝任何驅動程式,即可使用此連接器。

此連接器目前針對舊版驅動程式版本支援 10.x、11.x 版的 MariaDB,以及舊版驅動程式版本 10.0 到 10.5。

必要條件

如果您的資料存放區位於內部部署網路、Azure 虛擬網路或 Amazon 虛擬私人雲端中,則必須設定自我裝載整合執行階段以與其連線。

如果您的資料存放區是受控雲端資料服務,則可使用 Azure Integration Runtime。 如果只能存取防火牆規則中核准的 IP,您可以將 Azure Integration Runtime IP 新增至允許清單。

您也可以使用 Azure Data Factory 中的受控虛擬網路整合執行階段功能來存取內部部署網路,而不需要安裝和設定自我裝載整合執行階段。

如需 Data Factory 支援的網路安全性機制和選項的詳細資訊,請參閱資料存取策略

開始使用

若要透過管線執行複製活動,您可以使用下列其中一個工具或 SDK:

使用UI建立與 MariaDB 的連結服務

使用下列步驟,在 Azure 入口網站 UI 中建立與 MariaDB 的連結服務。

  1. 前往 Azure Data Factory 或 Synapse 工作區的 [管理] 索引標籤,選取 [連結服務],然後按一下 [新增]:

  2. 搜尋 Maria,然後選取 MariaDB 連接器。

    MariaDB 連接器的螢幕快照。

  3. 設定服務詳細資料,測試連線,然後建立新的連結服務。

    MariaDB 連結服務設定的螢幕快照。

連接器設定詳細資料

下列各節提供屬性的相關詳細數據,這些屬性是用來定義 MariaDB 連接器專屬的 Data Factory 實體。

連結服務屬性

如果您使用建議的驅動程式版本,MariaDB 連結服務支援下列屬性:

屬性 描述 必要
type type 屬性必須設定為: MariaDB Yes
driverVersion 當您選取建議的驅動程式版本時,驅動程式版本。 值為 v2。 Yes
伺服器 MariaDB 伺服器的名稱。 Yes
port 要連線到 MariaDB 伺服器的埠號碼。 No
database 您的 MariaDB 資料庫名稱。 Yes
username 您的用戶名稱。 Yes
password 用戶名稱的密碼。 將此欄位標記為 SecureString 以將其安全地儲存。 或者,可以參考 Azure Key Vault 中儲存的認證 Yes
connectVia 用於連線到資料存放區的 Integration Runtime。 深入了解必要條件一節。 如果未指定,就會使用預設的 Azure Integration Runtime。 No

範例:

{
    "name": "MariaDBLinkedService",
    "properties": {
        "type": "MariaDB",
        "typeProperties": {
            "server": "<server>",
            "port": "<port>",
            "database": "<database>",
            "username": "<username>",
            "password": {
                "type": "SecureString",
                "value": "<password>"
            },
            "driverVersion": "v2"
        },
        "connectVia": {
            "referenceName": "<name of Integration Runtime>",
            "type": "IntegrationRuntimeReference"
        }
    }
}

範例:在 Azure Key Vault 中儲存密碼

{
    "name": "MariaDBLinkedService",
    "properties": {
        "type": "MariaDB",
        "typeProperties": {
            "server": "<server>",
            "port": "<port>",
            "database": "<database>",
            "username": "<username>",
            "password": {
                "type": "AzureKeyVaultSecret",
                "store": {
                    "referenceName": "<Azure Key Vault linked service name>",
                    "type": "LinkedServiceReference"
                },
                "secretName": "<secretName>"
            },
            "driverVersion": "v2"
        },
        "connectVia": {
            "referenceName": "<name of Integration Runtime>",
            "type": "IntegrationRuntimeReference"
        }
    }
}

如果您使用舊版驅動程式,支援下列屬性:

屬性 描述 必要
type type 屬性必須設定為: MariaDB Yes
connectionString 要連線到 MariaDB 的 ODBC 連接字串。
您也可以將密碼放在 Azure Key Vault 中,並從連接字串中提取 pwd 組態。 請參閱下列範例和在 Azure Key Vault 中儲存認證一文中的更多詳細資料。
Yes
connectVia 用於連線到資料存放區的 Integration Runtime。 深入了解必要條件一節。 如果未指定,就會使用預設的 Azure Integration Runtime。 No

範例:

{
    "name": "MariaDBLinkedService",
    "properties": {
        "type": "MariaDB",
        "typeProperties": {
            "connectionString": "Server=<host>;Port=<port>;Database=<database>;UID=<user name>;PWD=<password>"
        },
        "connectVia": {
            "referenceName": "<name of Integration Runtime>",
            "type": "IntegrationRuntimeReference"
        }
    }
}

資料集屬性

如需可用來定義資料集的區段和屬性完整清單,請參閱資料集一文。 本節提供 MariaDB 資料集所支持的屬性清單。

若要從 MariaDB 複製數據,請將數據集的 type 屬性設定為 MariaDBTable。 在此類型的資料集中,沒有任何其他類型特定的屬性。

範例

{
    "name": "MariaDBDataset",
    "properties": {
        "type": "MariaDBTable",
        "typeProperties": {},
        "schema": [],
        "linkedServiceName": {
            "referenceName": "<MariaDB linked service name>",
            "type": "LinkedServiceReference"
        }
    }
}

複製活動屬性

如需可用來定義活動的區段和屬性完整清單,請參閱管線一文。 本節提供 MariaDB 來源所支持的屬性清單。

MariaDB 作為來源

若要從 MariaDB 複製數據,請將複製活動中的來源類型設定為 MariaDBSource。 複製活動的 source 區段支援下列屬性:

屬性 描述 必要
type 複製活動來源的類型屬性必須設定為: MariaDBSource Yes
query 使用自訂 SQL 查詢來讀取資料。 例如: "SELECT * FROM MyTable" 否 (如果已指定資料集中的 "tableName")

範例:

"activities":[
    {
        "name": "CopyFromMariaDB",
        "type": "Copy",
        "inputs": [
            {
                "referenceName": "<MariaDB input dataset name>",
                "type": "DatasetReference"
            }
        ],
        "outputs": [
            {
                "referenceName": "<output dataset name>",
                "type": "DatasetReference"
            }
        ],
        "typeProperties": {
            "source": {
                "type": "MariaDBSource",
                "query": "SELECT * FROM MyTable"
            },
            "sink": {
                "type": "<sink type>"
            }
        }
    }
]

MariaDB 的數據類型對應

從 MariaDB 複製數據時,下列對應會從 MariaDB 數據類型使用到服務內部使用的過渡數據類型。 請參閱 架構和數據類型對應 ,以瞭解複製活動如何將來源架構和數據類型對應至接收。

MariaDB 資料類型 過渡期服務資料類型 過渡期服務資料類型(適用於舊版驅動程式版本)
bigint Int64 Int64
bigint unsigned Decimal Decimal
bit(1) UInt64 Boolean
bit(M), M>1 UInt64 Byte[]
blob Byte[] Byte[]
bool Boolean
(If TreatTinyAsBoolean=false, it is mapped as SByte.TreatTinyAsBoolean 預設為 true )
Int16
char String String
date Datetime Datetime
datetime Datetime Datetime
decimal Decimal Decimal, String
double Double Double
double precision Double Double
enum String String
float Single Single
int Int32 Int32
int unsigned Int64 Int64
integer Int32 Int32
integer unsigned Int64 Int64
JSON String -
long varbinary Byte[] Byte[]
long varchar String String
longblob Byte[] Byte[]
longtext String String
mediumblob Byte[] Byte[]
mediumint Int32 Int32
mediumint unsigned Int64 Int64
mediumtext String String
numeric Decimal Decimal
real Double Double
set String String
smallint Int16 Int16
smallint unsigned Int32 Int32
text String String
time TimeSpan TimeSpan
timestamp Datetime Datetime
tinyblob Byte[] Byte[]
tinyint SByte Int16
tinyint unsigned Int16 Int16
tinytext String String
varchar String String
year Int Int

查閱活動屬性

若要了解屬性的詳細資料,請參閱查閱活動

升級 MariaDB 驅動程式版本

以下是可協助您升級 MariaDB 驅動程式版本的步驟:

  1. 在 [編輯鏈接服務] 頁面中,選取 [驅動程式版本] 底下的 [建議],並參考鏈接的服務屬性設定連結的服務。

  2. 最新 MariaDB 連結服務的數據類型對應與舊版的數據類型對應不同。 若要瞭解最新的數據類型對應,請參閱 MariaDB 的數據類型對應。

  3. 最新的驅動程式版本 v2 支援更多 MariaDB 版本。 如需詳細資訊,請參閱 支援的功能

下表顯示使用建議的驅動程式版本和使用舊版驅動程式版本之 MariaDB 連接器之間的數據類型對應差異。

MariaDB 資料類型 過渡期服務資料類型(使用建議的驅動程式版本) 過渡期服務資料類型 (使用舊版驅動程式版本)
bit(1) UInt64 布林值
bit(M), M>1 UInt64 Byte[]
bool 布林值 Int16
JSON String Byte[]

如需複製活動支援作為來源和接收器的資料存放區清單,請參閱支援的資料存放區