分享方式:


使用 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 連接器提供改良的原生 MariaDB 支援。 如果您使用舊版驅動程式版本,請在 2024 年 10 月 31 日之前升級驅動程式版本。 如需舊版與建議版本之間的差異詳細數據,請參閱本節

支援的功能

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

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

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

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

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

此連接器目前支援 MariaDB 版本 10.x、11.x,連接器需裝有新驅動程式版本 v2 (建議) 和舊版驅動程式版本 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 複製活動來源的 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
(若 TreatTinyAsBoolean=false,則對應為 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[]

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