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

# ClickHouse 字典源

> 将 ClickHouse 表配置为字典源。

设置示例：

<Tabs>
  <Tab title="DDL">
    ```sql theme={null}
    SOURCE(CLICKHOUSE(
        host 'example01-01-1'
        port 9000
        user 'default'
        password ''
        db 'default'
        table 'ids'
        where 'id=10'
        secure 1
        query 'SELECT id, value_1, value_2 FROM default.ids'
    ));
    ```
  </Tab>

  <Tab title="配置文件">
    ```xml theme={null}
    <source>
        <clickhouse>
            <host>example01-01-1</host>
            <port>9000</port>
            <user>default</user>
            <password></password>
            <db>default</db>
            <table>ids</table>
            <where>id=10</where>
            <secure>1</secure>
            <query>SELECT id, value_1, value_2 FROM default.ids</query>
        </clickhouse>
    </source>
    ```
  </Tab>
</Tabs>

<br />

设置字段：

| 设置 | 说明 |
| - | - |
| `host` | ClickHouse 主机。如果是本地主机，则查询会在没有任何网络通信的情况下处理。为提高容错能力，你可以创建一个 [Distributed](/zh/reference/engines/table-engines/special/distributed) 表，并在后续配置中填入该表。 |
| `port` | ClickHouse server 的端口。 |
| `user` | ClickHouse 用户名。 |
| `password` | ClickHouse 用户的密码。 |
| `db` | 数据库名称。 |
| `table` | 表名。 |
| `where` | 筛选条件。可选。 |
| `invalidate_query` | 用于检查字典状态的查询。可选。更多信息，请参见[使用 LIFETIME 刷新字典数据](/zh/reference/statements/create/dictionary/lifetime)一节。 |
| `secure` | 连接时使用 SSL。 |
| `query` | 自定义查询。可选。 |

<Note>
  `table` 或 `where` 字段不能与 `query` 字段同时使用。此外，必须声明 `table` 或 `query` 字段之一。
</Note>
