## モジュール 2：`TiDB Cloud Dedicated` クラスタへの接続

`TiDB Cloud Dedicated` には public endpoint、private endpoint、VPC peering で接続できます。このモジュールでは、public endpoint を使用します。

### 手順 1. `TiDB Cloud Dedicated` インターフェースを開く

+ `TiDB Cloud Dedicated` クラスタの名前をクリックします

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

### 手順 2. 接続を設定

+ 右上角の `Connect` をクリックして接続パネルを開きます。
+ `Connection Type` として `Public` を選択します。
+ 次に、`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
  ```

+ 次に、ローカルマシンから [Terminal 1](ssh://monitor1-ssh#1) に `ca.pem` の内容をコピーします。
+ `:` + `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.
  ...
  ```
