> ## 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.

# 更改 clickhouse-client 的提示符

> 本文介绍如何将 ClickHouse 客户端和 clickhouse-local 终端窗口中的提示符从 :) 更改为“前缀 + :)”

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>;
};

{frontMatter.description}

如果你不喜欢 `clickhouse client` 和 clickhouse-local 在终端窗口中显示的提示符样式，可以为其添加前缀进行修改。
本文将说明如何把提示符改成你想要的任意内容。

默认提示符是你的本地计算机名称，后跟 `:) `：

<Image img="https://mintcdn.com/private-7c7dfe99/mWK0LIJWA-YNz_kU/images/knowledgebase/change-the-prompt-in-clickhouse-client/0_prompt.webp?fit=max&auto=format&n=mWK0LIJWA-YNz_kU&q=85&s=27239daa242f5d20dba46fde96a2ff21" size="md" alt="默认 ClickHouse 客户端提示符" width="2289" height="411" data-path="images/knowledgebase/change-the-prompt-in-clickhouse-client/0_prompt.webp" />

以下是在提示符中可用的变量：`{user}`、`{host}`

更新提示符有几种方法，下面我们将逐一介绍。

<div id="--prompt-flag">
  ## --prompt 标志
</div>

修改该标志的第一种方法是使用 `--prompt`：

```bash theme={null}
clickhouse --prompt 👉
```

这会在笑脸前添加手指表情符号：

<Image img="https://mintcdn.com/private-7c7dfe99/mWK0LIJWA-YNz_kU/images/knowledgebase/change-the-prompt-in-clickhouse-client/1_prompt.webp?fit=max&auto=format&n=mWK0LIJWA-YNz_kU&q=85&s=27b3c2f290908c0804af7e01164ba73e" size="md" alt="带有手指表情符号的 ClickHouse 客户端 提示符" width="2298" height="386" data-path="images/knowledgebase/change-the-prompt-in-clickhouse-client/1_prompt.webp" />

<div id="config-file---top-level">
  ## 配置文件 - 顶层
</div>

或者，您也可以在 `config.xml` 文件中提供提示前缀：

```xml theme={null}
<config>
    <prompt>👉 </prompt>
</config>
```

```
clickhouse
```

<Image img="https://mintcdn.com/private-7c7dfe99/mWK0LIJWA-YNz_kU/images/knowledgebase/change-the-prompt-in-clickhouse-client/2_prompt.webp?fit=max&auto=format&n=mWK0LIJWA-YNz_kU&q=85&s=4fb0580c9948c21f456f5e7fabfa935a" size="md" alt="使用配置文件的 ClickHouse 客户端提示符" width="2307" height="769" data-path="images/knowledgebase/change-the-prompt-in-clickhouse-client/2_prompt.webp" />

我们可以使用任意名称的配置文件，并通过 `-C` 参数传入：

```xml theme={null}
<config>
    <prompt>🎄 </prompt>
</config>
```

```
clickhouse -C christmas.xml
```

<Image img="https://mintcdn.com/private-7c7dfe99/mWK0LIJWA-YNz_kU/images/knowledgebase/change-the-prompt-in-clickhouse-client/3_prompt.webp?fit=max&auto=format&n=mWK0LIJWA-YNz_kU&q=85&s=e29421fc104756cbe466f5182be1fbbe" size="md" alt="带有圣诞树表情符号的 ClickHouse 客户端 提示符" width="2314" height="781" data-path="images/knowledgebase/change-the-prompt-in-clickhouse-client/3_prompt.webp" />

想用 YAML 编写配置文件？
也完全可以：

```yaml theme={null}
prompt: 🟡
```

```bash theme={null}
clickhouse -C christmas.yaml
```

<Image img="https://mintcdn.com/private-7c7dfe99/mWK0LIJWA-YNz_kU/images/knowledgebase/change-the-prompt-in-clickhouse-client/4_prompt.webp?fit=max&auto=format&n=mWK0LIJWA-YNz_kU&q=85&s=77d8822797a72bc78898de9075472f9e" size="md" alt="带黄色圆圈表情符号的 ClickHouse 客户端 提示符" width="2302" height="600" data-path="images/knowledgebase/change-the-prompt-in-clickhouse-client/4_prompt.webp" />

<div id="config-file---connections_credentials">
  ## 配置文件 - connections\_credentials
</div>

或者，你也可以为每组连接凭据单独指定提示符。
这仅在使用 `clickhouse-client` 时才有意义。

```xml theme={null}
<config>
    <connections_credentials>
        <connection>
            <n>prod<n>
            <hostname>127.0.0.1</hostname>
            <port>9000</port>
            <secure>0</secure>
            <user>default</user>
            <prompt>\e[31m[PRODUCTION]\e[0m {user}@prod</prompt>
        </connection>
        <connection>
            <n>dev<n>
            <hostname>127.0.0.1</hostname>
            <port>9000</port>
            <secure>0</secure>
            <user>default</user>
            <prompt>\e[32m[DEVELOPMENT]\e[0m {user}@dev</prompt>
        </connection>
    </connections_credentials>
</config>
```

然后，我们可以尝试使用 `dev` 连接：

```bash theme={null}
clickhouse client -C connections.xml --connection dev
```

<Image img="https://mintcdn.com/private-7c7dfe99/mWK0LIJWA-YNz_kU/images/knowledgebase/change-the-prompt-in-clickhouse-client/5_prompt.webp?fit=max&auto=format&n=mWK0LIJWA-YNz_kU&q=85&s=c653e4bcd35e43dd63e2d92cb362d721" size="md" alt="带有 Development 连接的 ClickHouse 客户端 提示符" width="1310" height="203" data-path="images/knowledgebase/change-the-prompt-in-clickhouse-client/5_prompt.webp" />

或者是 `prod`：

```bash theme={null}
clickhouse client -C connections.xml --connection prod
```

<Image img="https://mintcdn.com/private-7c7dfe99/mWK0LIJWA-YNz_kU/images/knowledgebase/change-the-prompt-in-clickhouse-client/6_prompt.webp?fit=max&auto=format&n=mWK0LIJWA-YNz_kU&q=85&s=48950664621db5870fe0be537b66a65d" size="md" alt="带有生产环境连接的 ClickHouse 客户端提示符" width="1297" height="189" data-path="images/knowledgebase/change-the-prompt-in-clickhouse-client/6_prompt.webp" />

以下是 YAML 版本：

```yaml theme={null}
connections_credentials:
  connection:
    - name: prod
      hostname: 127.0.0.1
      port: 9000
      secure: 0
      user: default
      prompt: "\e[35m[PRODUCTION]\e[0m {user}@{host}"
    - name: dev
      hostname: 127.0.0.1
      port: 9000
      secure: 0
      user: default
      prompt: "\e[34m[DEVELOPMENT]\e[0m {user}@{host}"
```

使用 `dev` 连接时：

```bash theme={null}
clickhouse client -C connections.yaml --connection dev
```

<Image img="https://mintcdn.com/private-7c7dfe99/mWK0LIJWA-YNz_kU/images/knowledgebase/change-the-prompt-in-clickhouse-client/7_prompt.webp?fit=max&auto=format&n=mWK0LIJWA-YNz_kU&q=85&s=0369e94e271f49c2b1e85f5ee9357f60" size="md" alt="使用 YAML 配置的 development 连接的 ClickHouse 客户端 提示符" width="1581" height="169" data-path="images/knowledgebase/change-the-prompt-in-clickhouse-client/7_prompt.webp" />

接下来是 `prod`：

```bash theme={null}
clickhouse client -C connections.yaml --connection prod
```

<Image img="https://mintcdn.com/private-7c7dfe99/mWK0LIJWA-YNz_kU/images/knowledgebase/change-the-prompt-in-clickhouse-client/8_prompt.webp?fit=max&auto=format&n=mWK0LIJWA-YNz_kU&q=85&s=900304317244a1203fc69a4b9464686d" size="md" alt="使用 YAML 配置生产环境连接的 ClickHouse 客户端 提示符" width="1525" height="187" data-path="images/knowledgebase/change-the-prompt-in-clickhouse-client/8_prompt.webp" />
