> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-detect-table-modification.mintlify.site/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>;
};

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

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

<Image img="https://mintcdn.com/private-7c7dfe99-detect-table-modification/khTo4jdOlx_yU9ob/images/knowledgebase/change-the-prompt-in-clickhouse-client/0_prompt.webp?fit=max&auto=format&n=khTo4jdOlx_yU9ob&q=85&s=795bd04f063883bd9d07e96f13333b62" 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-detect-table-modification/khTo4jdOlx_yU9ob/images/knowledgebase/change-the-prompt-in-clickhouse-client/1_prompt.webp?fit=max&auto=format&n=khTo4jdOlx_yU9ob&q=85&s=5dd87c77648a5180e7f5139b8196f531" 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-detect-table-modification/khTo4jdOlx_yU9ob/images/knowledgebase/change-the-prompt-in-clickhouse-client/2_prompt.webp?fit=max&auto=format&n=khTo4jdOlx_yU9ob&q=85&s=3a22bd3631147f1b8992b1c52d0d8aba" 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-detect-table-modification/khTo4jdOlx_yU9ob/images/knowledgebase/change-the-prompt-in-clickhouse-client/3_prompt.webp?fit=max&auto=format&n=khTo4jdOlx_yU9ob&q=85&s=f9e3e4849a9cf2fd44769654142359bd" 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-detect-table-modification/khTo4jdOlx_yU9ob/images/knowledgebase/change-the-prompt-in-clickhouse-client/4_prompt.webp?fit=max&auto=format&n=khTo4jdOlx_yU9ob&q=85&s=3f6a29e782a4a328af422f9b36922ea7" 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-detect-table-modification/khTo4jdOlx_yU9ob/images/knowledgebase/change-the-prompt-in-clickhouse-client/5_prompt.webp?fit=max&auto=format&n=khTo4jdOlx_yU9ob&q=85&s=f650a375acbd7fc9fb0f8d0eee647fc5" 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-detect-table-modification/khTo4jdOlx_yU9ob/images/knowledgebase/change-the-prompt-in-clickhouse-client/6_prompt.webp?fit=max&auto=format&n=khTo4jdOlx_yU9ob&q=85&s=48809cc37214cd3165824e65124847ed" 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-detect-table-modification/khTo4jdOlx_yU9ob/images/knowledgebase/change-the-prompt-in-clickhouse-client/7_prompt.webp?fit=max&auto=format&n=khTo4jdOlx_yU9ob&q=85&s=635f7ed0b8bb831f5698fef9288154cf" 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-detect-table-modification/khTo4jdOlx_yU9ob/images/knowledgebase/change-the-prompt-in-clickhouse-client/8_prompt.webp?fit=max&auto=format&n=khTo4jdOlx_yU9ob&q=85&s=32d8fe5aee7e62982707ef1152407f78" size="md" alt="使用 YAML 配置生产环境连接的 ClickHouse 客户端 提示符" width="1525" height="187" data-path="images/knowledgebase/change-the-prompt-in-clickhouse-client/8_prompt.webp" />
