> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-mintlify-8c05c8a2.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> 通过 BladePipe 数据管道将流式数据导入 ClickHouse

# 将 BladePipe 连接到 ClickHouse

export const PartnerBadge = () => {
  return <div className="PartnerBadge">
            <div className="PartnerBadgeIcon">
                <svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
                    <polyline points="12.5 9.5 10 12 6 11 2.5 8.5" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" strokeWidth="1" />
                    <polyline points="4.54 4.41 8 3.5 11.46 4.41" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" strokeWidth="1" />
                    <path d="M2.15,3.78 L0.55,6.95 A0.5,0.5 0,0,0 0.77,7.62 L2.5,8.5 L4.54,4.41 L2.82,3.55 A0.5,0.5 0,0,0 2.15,3.78 Z" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" strokeWidth="1" />
                    <path d="M13.5,8.5 L15.23,7.62 A0.5,0.5 0,0,0 15.45,6.95 L13.85,3.78 A0.5,0.5 0,0,0 13.18,3.55 L11.46,4.41 Z" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" strokeWidth="1" />
                    <path d="M11.5,4.5 L9,4.5 L6.15,7.27 A0.5,0.5 0,0,0 6.24,8.05 C7.33,8.74 8.81,8.72 10,7.5 L12.5,9.5 L13.5,8.5" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" strokeWidth="1" />
                    <polyline points="7.75 13.5 5.15 12.85 3.5 11.67" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" strokeWidth="1" />
                </svg>
            </div>
            合作伙伴集成
        </div>;
};

export const Image = ({img, alt, size}) => {
  return <Frame>
      <img src={img} alt={alt} />
    </Frame>;
};

<a href="https://www.bladepipe.com/" target="_blank">BladePipe</a> 是一款实时端到端数据集成工具，具备亚秒级时延，可实现跨平台间的无缝数据流转。

ClickHouse 是 BladePipe 的预置连接器之一，用户可以通过它自动将来自各种数据源的数据集成到 ClickHouse 中。本页将分步介绍如何将数据实时加载到 ClickHouse。

<div id="supported-sources">
  ## 支持的数据源
</div>

目前，BladePipe 支持从以下数据源将数据集成至 ClickHouse：

* MySQL/MariaDB/AuroraMySQL
* Oracle
* PostgreSQL/AuroraPostgreSQL
* MongoDB
* Kafka
* PolarDB-MySQL
* OceanBase
* TiDB

后续还将支持更多数据源。

<Steps>
  <Step>
    ## 下载并运行 BladePipe

    1. 登录 <a href="https://www.bladepipe.com/" target="_blank">BladePipe Cloud</a>。

    2. 按照 <a href="https://doc.bladepipe.com/productOP/byoc/installation/install_worker_docker" target="_blank">安装 Worker (Docker) </a> 或 <a href="https://doc.bladepipe.com/productOP/byoc/installation/install_worker_binary" target="_blank">安装 Worker (二进制) </a> 中的说明，下载并安装 BladePipe Worker。

    <Note>
      您也可以选择下载并部署 <a href="https://doc.bladepipe.com/productOP/onPremise/installation/install_all_in_one_binary" target="_blank">BladePipe Enterprise</a>。
    </Note>
  </Step>

  <Step>
    ## 将 ClickHouse 添加为目标

    <Note>
      1. BladePipe 支持 ClickHouse `20.12.3.3` 及以上版本。
      2. 若要将 ClickHouse 用作目标，请确保该用户具有 SELECT、INSERT 和常见 DDL 权限。
    </Note>

    1. 在 BladePipe 中，点击 "DataSource" > "Add DataSource"。

    2. 选择 `ClickHouse`，然后填写相关设置，包括 ClickHouse 的主机和端口、用户名和密码，并点击 "Test Connection"。

           <Image img="https://mintcdn.com/private-7c7dfe99-mintlify-8c05c8a2/rblGsP0EjEHvjMiq/images/integrations/data-ingestion/etl-tools/bp_ck_1.png?fit=max&auto=format&n=rblGsP0EjEHvjMiq&q=85&s=7f5268ab1187ee35c933b82231a4033f" size="lg" border alt="将 ClickHouse 添加为目标" width="1882" height="1744" data-path="images/integrations/data-ingestion/etl-tools/bp_ck_1.png" />

    3. 点击底部的 "Add DataSource"，即可添加一个 ClickHouse 实例。
  </Step>

  <Step>
    ## 将 MySQL 添加为源

    在本教程中，我们将使用 MySQL 实例作为源，并介绍将 MySQL 数据加载到 ClickHouse 的过程。

    <Note>
      要使用 MySQL 作为源，请确保该用户具有<a href="https://doc.bladepipe.com/dataMigrationAndSync/datasource_func/MySQL/privs_for_mysql" target="_blank">所需权限</a>。
    </Note>

    1. 在 BladePipe 中，点击 "DataSource" > "Add DataSource"。

    2. 选择 `MySQL`，然后填写相关设置，输入 MySQL 主机和端口、用户名和密码，再点击 "Test Connection"。

           <Image img="https://mintcdn.com/private-7c7dfe99-mintlify-8c05c8a2/rblGsP0EjEHvjMiq/images/integrations/data-ingestion/etl-tools/bp_ck_2.png?fit=max&auto=format&n=rblGsP0EjEHvjMiq&q=85&s=67c0c58f0fdd861d8f56f4befb92ae50" size="lg" border alt="将 MySQL 添加为源" width="1882" height="1746" data-path="images/integrations/data-ingestion/etl-tools/bp_ck_2.png" />

    3. 点击底部的 "Add DataSource"，即可添加 MySQL 实例。
  </Step>

  <Step>
    ## 创建管道

    1. 在 BladePipe 中，点击 "DataJob" > "Create DataJob"。

    2. 选择已添加的 MySQL 和 ClickHouse 实例，点击 "Test Connection"，确认 BladePipe 已连接到这些实例。然后，选择要迁移的数据库。
           <Image img="https://mintcdn.com/private-7c7dfe99-mintlify-8c05c8a2/rblGsP0EjEHvjMiq/images/integrations/data-ingestion/etl-tools/bp_ck_3.png?fit=max&auto=format&n=rblGsP0EjEHvjMiq&q=85&s=cff61ddede5e966ecde7d497adf6b346" size="lg" border alt="选择源和目标" width="3264" height="1904" data-path="images/integrations/data-ingestion/etl-tools/bp_ck_3.png" />

    3. 在 DataJob Type 中选择 "Incremental"，同时勾选 "Full Data" 选项。
           <Image img="https://mintcdn.com/private-7c7dfe99-mintlify-8c05c8a2/rblGsP0EjEHvjMiq/images/integrations/data-ingestion/etl-tools/bp_ck_4.png?fit=max&auto=format&n=rblGsP0EjEHvjMiq&q=85&s=029279ea85e4ff3143bbbf485f651e26" size="lg" border alt="选择同步类型" width="2248" height="1884" data-path="images/integrations/data-ingestion/etl-tools/bp_ck_4.png" />

    4. 选择要复制的表。
           <Image img="https://mintcdn.com/private-7c7dfe99-mintlify-8c05c8a2/rblGsP0EjEHvjMiq/images/integrations/data-ingestion/etl-tools/bp_ck_5.png?fit=max&auto=format&n=rblGsP0EjEHvjMiq&q=85&s=628a6142dd5b58c2f4f0e4f2dd636928" size="lg" border alt="选择表" width="2956" height="1730" data-path="images/integrations/data-ingestion/etl-tools/bp_ck_5.png" />

    5. 选择要复制的列。
           <Image img="https://mintcdn.com/private-7c7dfe99-mintlify-8c05c8a2/rblGsP0EjEHvjMiq/images/integrations/data-ingestion/etl-tools/bp_ck_6.png?fit=max&auto=format&n=rblGsP0EjEHvjMiq&q=85&s=0f1c8907002fb5c8bf7b7c592675c348" size="lg" border alt="选择列" width="2960" height="1738" data-path="images/integrations/data-ingestion/etl-tools/bp_ck_6.png" />

    6. 确认创建 DataJob 后，DataJob 会自动运行。
           <Image img="https://mintcdn.com/private-7c7dfe99-mintlify-8c05c8a2/rblGsP0EjEHvjMiq/images/integrations/data-ingestion/etl-tools/bp_ck_8.png?fit=max&auto=format&n=rblGsP0EjEHvjMiq&q=85&s=4cd7a6246ee7f74008f24bca0515b1f1" size="lg" border alt="DataJob 正在运行" width="2244" height="294" data-path="images/integrations/data-ingestion/etl-tools/bp_ck_8.png" />
  </Step>

  <Step>
    ## 验证数据

    1. 停止向 MySQL 实例写入数据，并等待 ClickHouse 完成数据合并。

    <Note>
      由于 ClickHouse 自动合并的时机不可预测，你可以手动运行 `OPTIMIZE TABLE xxx FINAL;` 命令来触发一次合并。请注意，这种手动合并并不一定每次都能成功。

      或者，你也可以运行 `CREATE VIEW xxx_v AS SELECT * FROM xxx FINAL;` 命令创建一个视图，并在该视图上执行查询，以确保数据已完全合并。
    </Note>

    2. 创建一个 <a href="https://doc.bladepipe.com/operation/job_manage/create_job/create_period_verification_correction_job" target="_blank">验证 DataJob</a>。验证 DataJob 完成后，请检查结果，确认 ClickHouse 中的数据与 MySQL 中的数据一致。
           <Image img="https://mintcdn.com/private-7c7dfe99-mintlify-8c05c8a2/rblGsP0EjEHvjMiq/images/integrations/data-ingestion/etl-tools/bp_ck_9.png?fit=max&auto=format&n=rblGsP0EjEHvjMiq&q=85&s=0f42532ff4fd6e2b1d350376511bf1c0" size="lg" border alt="验证数据" width="2234" height="286" data-path="images/integrations/data-ingestion/etl-tools/bp_ck_9.png" />
  </Step>
</Steps>
