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

> 在熟悉的笔记本环境中高效查询超大规模数据集，并轻松进行分析和建模。

# 将 ClickHouse 连接到 Deepnote

export const CommunityMaintainedBadge = () => {
  return <div className="CommunityMaintainedBadge">
            <div className="CommunityMaintainedIcon">
            <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor" viewBox="0 0 256 256">
                <path d="M244.8,150.4a8,8,0,0,1-11.2-1.6A51.6,51.6,0,0,0,192,128a8,8,0,0,1-7.37-4.89,8,8,0,0,1,0-6.22A8,8,0,0,1,192,112a24,24,0,1,0-23.24-30,8,8,0,1,1-15.5-4A40,40,0,1,1,219,117.51a67.94,67.94,0,0,1,27.43,21.68A8,8,0,0,1,244.8,150.4ZM190.92,212a8,8,0,1,1-13.84,8,57,57,0,0,0-98.16,0,8,8,0,1,1-13.84-8,72.06,72.06,0,0,1,33.74-29.92,48,48,0,1,1,58.36,0A72.06,72.06,0,0,1,190.92,212ZM128,176a32,32,0,1,0-32-32A32,32,0,0,0,128,176ZM72,120a8,8,0,0,0-8-8A24,24,0,1,1,87.24,82a8,8,0,1,0,15.5-4A40,40,0,1,0,37,117.51,67.94,67.94,0,0,0,9.6,139.19a8,8,0,1,0,12.8,9.61A51.6,51.6,0,0,1,64,128,8,8,0,0,0,72,120Z"></path>
            </svg>
        </div>
            Community Maintained
        </div>;
};

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

<a href="https://www.deepnote.com/" target="_blank">Deepnote</a> 是一个面向团队的协作式数据 笔记本，用于帮助团队发现并共享洞察。除了兼容 Jupyter 之外，它还支持在云端运行，并为你提供一个统一的平台，以便高效协作和开展数据科学项目。

本指南假定你已拥有 Deepnote 账户，并且已有一个正在运行的 ClickHouse 实例。

<div id="interactive-example">
  ## 交互式示例
</div>

如果你想查看一个通过 Deepnote 数据笔记本查询 ClickHouse 的交互式示例，请点击下方按钮，启动一个连接到 [ClickHouse playground](/zh/get-started/sample-datasets/playground) 的模板项目。

[<img src="https://deepnote.com/buttons/launch-in-deepnote.svg" alt="在 Deepnote 中启动" width="32" />](https://deepnote.com/launch?template=ClickHouse%20and%20Deepnote)

<div id="connect-to-clickhouse">
  ## 连接到 ClickHouse
</div>

1. 在 Deepnote 中，选择“Integrations”概览，然后点击 ClickHouse 卡片。

<Image size="lg" img="https://mintcdn.com/private-7c7dfe99-fix-nav-issues/4Hi2sd8mn4aAdMgN/images/integrations/data-visualization/deepnote_01.png?fit=max&auto=format&n=4Hi2sd8mn4aAdMgN&q=85&s=853f0474026b4afc35c60a32107230db" alt="ClickHouse 集成卡片" border width="3024" height="1368" data-path="images/integrations/data-visualization/deepnote_01.png" />

2. 填写 ClickHouse 实例的连接信息：

要通过 HTTP(S) 连接到 ClickHouse，你需要以下信息：

| Parameter(s)              | Description                                |
| ------------------------- | ------------------------------------------ |
| `HOST` and `PORT`         | 通常，使用 TLS 时端口为 8443；不使用 TLS 时端口为 8123。     |
| `DATABASE NAME`           | 默认情况下，存在一个名为 `default` 的数据库。请使用你要连接的数据库名称。 |
| `USERNAME` and `PASSWORD` | 默认情况下，用户名为 `default`。请根据你的使用场景使用相应的用户名。    |

你的 ClickHouse Cloud 服务的连接信息可在 ClickHouse Cloud 控制台中查看。
选择一个服务，然后点击 **Connect**：

<Image img="https://mintcdn.com/private-7c7dfe99-fix-nav-issues/1oh4rjwfuHRS2yL2/images/_snippets/cloud-connect-button.png?fit=max&auto=format&n=1oh4rjwfuHRS2yL2&q=85&s=81c1524ac8ac2dac27e1558f13fcfd29" size="md" alt="ClickHouse Cloud 服务连接按钮" border width="998" height="932" data-path="images/_snippets/cloud-connect-button.png" />

选择 **HTTPS**。连接信息会显示在示例 `curl` 命令中。

<Image img="https://mintcdn.com/private-7c7dfe99-fix-nav-issues/1oh4rjwfuHRS2yL2/images/_snippets/connection-details-https.png?fit=max&auto=format&n=1oh4rjwfuHRS2yL2&q=85&s=335e19954512afe36d735a736cd32be7" size="md" alt="ClickHouse Cloud HTTPS 连接信息" border width="1320" height="1184" data-path="images/_snippets/connection-details-https.png" />

如果你使用的是自管理 ClickHouse，则连接信息由你的 ClickHouse 管理员配置。

<Image size="md" img="https://mintcdn.com/private-7c7dfe99-fix-nav-issues/4Hi2sd8mn4aAdMgN/images/integrations/data-visualization/deepnote_02.png?fit=max&auto=format&n=4Hi2sd8mn4aAdMgN&q=85&s=ca6d9d95621b8a2bf179f9d351acd3b3" alt="ClickHouse 详情对话框" border width="1827" height="1061" data-path="images/integrations/data-visualization/deepnote_02.png" />

***注意：*** 如果您与 ClickHouse 的连接受 IP Access List 保护，可能需要将 Deepnote 的 IP 地址加入允许列表。更多信息请参阅 [Deepnote 文档](https://docs.deepnote.com/integrations/authorize-connections-from-deepnote-ip-addresses)。

3. 恭喜！您已成功将 ClickHouse 集成到 Deepnote 中。

<div id="using-clickhouse-integration">
  ## 使用 ClickHouse 集成
</div>

1. 首先，连接到 笔记本 右侧的 ClickHouse 集成。

   <Image size="lg" img="https://mintcdn.com/private-7c7dfe99-fix-nav-issues/4Hi2sd8mn4aAdMgN/images/integrations/data-visualization/deepnote_03.png?fit=max&auto=format&n=4Hi2sd8mn4aAdMgN&q=85&s=eaaa7e26ddf8a1acb36f9e7bfe47042b" alt="ClickHouse 详细信息对话框" border width="3008" height="1086" data-path="images/integrations/data-visualization/deepnote_03.png" />

2. 现在，新建一个 ClickHouse 查询块，并查询你的数据库。查询结果将保存为 DataFrame，并存储在 SQL 块中指定的变量中。

3. 你也可以将任何现有的 [SQL 块](https://docs.deepnote.com/features/sql-cells) 转换为 ClickHouse 块。
