## 模块 2：连接到 `TiDB Cloud Dedicated` 集群

您可以通过 public endpoint、private endpoint 和 VPC 对等连接来连接到 `TiDB Cloud Dedicated`。在本模块中，我们将使用 public endpoint。

### 步骤 1. 打开 `TiDB Cloud Dedicated` 界面

+ 点击您的 `TiDB Cloud Dedicated` 集群名称

  ![80%](https://lab-static.pingcap.com/images/2025/7/25/35e535664fc068aa481769714f4c6a37380cea7c.png)

### 步骤 2. 配置连接

+ 点击右上角的 `Connect` 打开连接面板。
+ 选择 `Public` 作为 `Connection Type`。
+ 然后，点击 `Configure IP Access List`。

  ![80%](https://lab-static.pingcap.com/images/2025/7/25/b83385d1d9be8172d1a18a58f483be07aa35e088.png)

+ 选择 `Allow access from anywhere`。
+ 然后，点击 `Comfirm`。

> [!TIP]
> 在生产环境中不建议使用 `Allow access from anywhere`。

### 步骤 3. 完成安全设置

+ 点击 `Set Root Password`，并设置 root 密码。
+ 然后，下载 CA 证书。

  ![80%](https://lab-static.pingcap.com/images/2025/7/25/ffac8332817e6cf89cd7b9fb4385d047c5b754c3.png)

### 步骤 4. 获取连接命令

+ 选择使用 `MySQL CLi` 连接

  ![80%](https://lab-static.pingcap.com/images/2025/7/25/54f577c9682875874ebc1ff62693957f21c19a87.png)

+ 复制连接命令。

### 步骤 5. 打开 [Terminal 1](ssh://monitor1-ssh#1)

### 步骤 6. 复制 `ca.pem`

  ```bash
  vi ca.pem
  ```

+ 然后，将本地机器上的 `ca.pem` 内容复制到 [Terminal 1](ssh://monitor1-ssh#1)。
+ 输入 `:` + `wq!` 退出。

### 步骤 7. 连接到 `TiDB Cloud Dedicated`

+ 将步骤 4 中获得的连接命令粘贴到终端中。

  ```bash
  mysql --comments -u 'root' -h <host_url> -P 4000 -D 'test' --ssl-mode=VERIFY_IDENTITY --ssl-ca=/home/ubuntu/ca.pem -p'<PASSWORD>'
  ```

  ```output
  ...
  Your MySQL connection id is 227
  Server version: 8.0.11-TiDB-v8.5.2 TiDB Server (Apache License 2.0) Enterprise Edition, MySQL 8.0 compatible

  Copyright (c) 2000, 2025, Oracle and/or its affiliates.

  Oracle is a registered trademark of Oracle Corporation and/or its
  affiliates. Other names may be trademarks of their respective owners.
  ...
  ```
