> ## Documentation Index
> Fetch the complete documentation index at: https://clickhouse.com/docs/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 = "lg"}) => {
  const normalizedSize = ["sm", "md", "lg"].includes(size) ? size : "lg";
  return <div className={`ch-image-${normalizedSize}`}>
      <Frame>
        <img src={img} alt={alt} />
      </Frame>
    </div>;
};

<PartnerBadge />

<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 title="下载并运行 BladePipe" id="1-run-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 title="将 ClickHouse 添加为目标" id="2-add-clickhouse-as-a-target">
    <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/pIetLsS_hOGHqoPJ/images/integrations/data-ingestion/etl-tools/bp_ck_1.webp?fit=max&auto=format&n=pIetLsS_hOGHqoPJ&q=85&s=63b11e4a76a8fedaf8a98c4d3a496fa6" size="lg" border alt="将 ClickHouse 添加为目标" width="1882" height="1744" data-path="images/integrations/data-ingestion/etl-tools/bp_ck_1.webp" />

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

  <Step title="将 MySQL 添加为源" id="3-add-mysql-as-a-source">
    在本教程中，我们将使用 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/pIetLsS_hOGHqoPJ/images/integrations/data-ingestion/etl-tools/bp_ck_2.webp?fit=max&auto=format&n=pIetLsS_hOGHqoPJ&q=85&s=86149981e4823e8ffc94d870405a0674" size="lg" border alt="将 MySQL 添加为源" width="1882" height="1746" data-path="images/integrations/data-ingestion/etl-tools/bp_ck_2.webp" />

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

  <Step title="创建管道" id="4-create-a-pipeline">
    1. 在 BladePipe 中，点击 "DataJob" > "Create DataJob"。

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

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

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

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

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

  <Step title="验证数据" id="5-verify-the-data">
    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/pIetLsS_hOGHqoPJ/images/integrations/data-ingestion/etl-tools/bp_ck_9.webp?fit=max&auto=format&n=pIetLsS_hOGHqoPJ&q=85&s=85a6aedaebcf7d61338b632241660fda" size="lg" border alt="验证数据" width="2234" height="286" data-path="images/integrations/data-ingestion/etl-tools/bp_ck_9.webp" />
  </Step>
</Steps>
