Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapt Serverless Tier in Developer Guide (#11125) #11231

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions TOC-tidb-cloud.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@
- Quick Start
- [Build a TiDB Cluster in TiDB Cloud (Serverless Tier)](/develop/dev-guide-build-cluster-in-cloud.md)
- [CRUD SQL in TiDB](/develop/dev-guide-tidb-crud-sql.md)
- Build a Simple CRUD App with TiDB
- [Java](/develop/dev-guide-sample-application-java.md)
- [Golang](/develop/dev-guide-sample-application-golang.md)
- Example Applications
- [Build a TiDB Application using Spring Boot](/develop/dev-guide-sample-application-spring-boot.md)
- [Java](/develop/dev-guide-sample-application-java.md)
- [Java (Spring Boot)](/develop/dev-guide-sample-application-spring-boot.md)
- [Golang](/develop/dev-guide-sample-application-golang.md)
- Connect to TiDB
- [Choose Driver or ORM](/develop/dev-guide-choose-driver-or-orm.md)
- [Connect to TiDB](/develop/dev-guide-connect-to-tidb.md)
Expand Down
7 changes: 3 additions & 4 deletions TOC.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@
- Quick Start
- [Build a TiDB Cluster in TiDB Cloud (Serverless Tier)](/develop/dev-guide-build-cluster-in-cloud.md)
- [CRUD SQL in TiDB](/develop/dev-guide-tidb-crud-sql.md)
- Build a Simple CRUD App with TiDB
- [Java](/develop/dev-guide-sample-application-java.md)
- [Golang](/develop/dev-guide-sample-application-golang.md)
- Example Applications
- [Build a TiDB Application using Spring Boot](/develop/dev-guide-sample-application-spring-boot.md)
- [Java](/develop/dev-guide-sample-application-java.md)
- [Java (Spring Boot)](/develop/dev-guide-sample-application-spring-boot.md)
- [Golang](/develop/dev-guide-sample-application-golang.md)
- Connect to TiDB
- [Choose Driver or ORM](/develop/dev-guide-choose-driver-or-orm.md)
- [Connect to TiDB](/develop/dev-guide-connect-to-tidb.md)
Expand Down
85 changes: 35 additions & 50 deletions develop/dev-guide-build-cluster-in-cloud.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,19 @@ This document walks you through the quickest way to get started with TiDB Cloud.

## Step 1. Create a free cluster

1. If you do not have a TiDB Cloud account, click [TiDB Cloud](https://tidbcloud.com/free-trial) to sign up for an account.
2. [Sign in](https://tidbcloud.com/) with your TiDB Cloud account.
3. To create a Serverless Tier cluster for free, you can either select the **Serverless Tier** plan on the [plan page](https://tidbcloud.com/console/plans) or click **Create Cluster** on the [**Clusters**](https://tidbcloud.com/console/clusters) page.
4. On the **Create Cluster** page, set up your cluster name, cloud provider (for now, only AWS is available for Serverless Tier), and region (a nearby region is recommended). Then click **Create** to create your cluster.
1. If you do not have a TiDB Cloud account, click [here](https://tidbcloud.com/free-trial) to sign up for an account.

The cluster creation process starts and the **Security Settings** dialog box is displayed.
2. [Log in](https://tidbcloud.com/) to your TiDB Cloud account.

5. In the **Security Settings** dialog box, set the root password and allowed IP addresses to connect to your cluster, and then click **Apply**.
3. On the **Clusters** page, click **Create Cluster**.

Your TiDB Cloud cluster will be created in approximately 5 to 15 minutes.
4. On the **Create Cluster** page, **Serverless Tier** is selected by default. Update the default cluster name if necessary, and then select the region where you want to create your cluster.

6. After creating a cluster, click **Connect** in the upper-right corner. A connection dialog box is displayed.
Your TiDB Cloud cluster will be created in approximately 30 seconds.

> **Tip:**
>
> Alternatively, you can also click the name of your newly created cluster to go to the cluster details page, and then click **Connect** in the upper-right corner.
6. After your TiDB Cloud cluster is created, click **Security Settings**. In the **Security Settings** dialog box, set a root password to connect to your cluster, and then click **Submit**. If you do not set a root password, you cannot connect to the cluster.

7. In the dialog box, locate **Step 2: Connect with a SQL client**, and then copy the string to connect with a SQL client for later use.
7. Click **Connect**. A connection dialog box is displayed. Under **Connect with a SQL Client** in the dialog, click the tab of your preferred connection method, and then save the corresponding connection string. The following section uses MySQL client as an example.

<CustomContent platform="tidb">

Expand Down Expand Up @@ -146,55 +141,45 @@ mysql Ver 15.1 Distrib 5.5.68-MariaDB, for Linux (x86_64) using readline 5.1
{{< copyable "shell-regular" >}}

```shell
mysql --connect-timeout 15 -u '<prefix>.root' -h <host> -P 4000 -p
mysql --connect-timeout 15 -u '<prefix>.root' -h <host> -P 4000 -D test --ssl-mode=VERIFY_IDENTITY --ssl-ca=/etc/ssl/cert.pem -p
```

3. Fill in the password to sign in.

## Step 3. Run the sample application

1. Clone the `tidb-example-java` project:

{{< copyable "shell-regular" >}}
<CustomContent platform="tidb">

```shell
git clone https://github.com/pingcap-inc/tidb-example-java.git
```
> **Note:**
>
> - When you connect to a Serverless Tier cluster, you must [use the TLS connection](https://docs.pingcap.com/tidbcloud/secure-connections-to-serverless-tier-clusters).
> - If you encounter problems when connecting to a Serverless Tier cluster, you can read [Secure Connections to Serverless Tier Clusters](https://docs.pingcap.com/tidbcloud/secure-connections-to-serverless-tier-clusters) for more information.

2. Change connection parameters.
</CustomContent>

In `plain-java-jdbc/src/main/java/com/pingcap/JDBCExample.java`, modify the parameters of the host, port, user, and password:
<CustomContent platform="tidb-cloud">

{{< copyable "" >}}
> **Note:**
>
> - When you connect to a Serverless Tier cluster, you must [use the TLS connection](/tidb-cloud/secure-connections-to-serverless-tier-clusters.md).
> - If you encounter problems when connecting to a Serverless Tier cluster, you can read [Secure Connections to Serverless Tier Clusters](/tidb-cloud/secure-connections-to-serverless-tier-clusters.md) for more information.

```java
mysqlDataSource.setServerName("localhost");
mysqlDataSource.setPortNumber(4000);
mysqlDataSource.setDatabaseName("test");
mysqlDataSource.setUser("root");
mysqlDataSource.setPassword("");
```

Suppose that the password you set is `123456` and the connection string you get from TiDB Cloud is the following:
</CustomContent>

{{< copyable "" >}}
3. Fill in the password to sign in.

```shell
mysql --connect-timeout 15 -u '4JC1i9KroBMFRwW.root' -h xxx.tidbcloud.com -P 4000 -D test -p
```
## Step 3. Execute a SQL statement

In this case, you can modify the parameters as follows:
Let's try to execute your first SQL statement on TiDB Cloud.

{{< copyable "" >}}
```sql
SELECT 'Hello TiDB Cloud!';
```

```java
mysqlDataSource.setServerName("xxx.tidbcloud.com");
mysqlDataSource.setPortNumber(4000);
mysqlDataSource.setDatabaseName("test");
mysqlDataSource.setUser("4JC1i9KroBMFRwW.root");
mysqlDataSource.setPassword("123456");
```
Expected output:

3. Run `make plain-java-jdbc`.
```sql
+-------------------+
| Hello TiDB Cloud! |
+-------------------+
| Hello TiDB Cloud! |
+-------------------+
```

Here is an example of the [expected output](https://github.com/pingcap-inc/tidb-example-java/blob/main/Expected-Output.md#plain-java-jdbc).
If your actual output is similar to the expected output, congratulations, you have successfully execute a SQL statement on TiDB Cloud.
40 changes: 24 additions & 16 deletions develop/dev-guide-sample-application-golang.md
Original file line number Diff line number Diff line change
Expand Up @@ -792,52 +792,60 @@ When using go-sql-driver/mysql, you need to connect to your cluster and run the

<div label="Using GORM (Recommended)" value="gorm">

If you are using a non-local default cluster, such as TiDB Cloud or other remote clusters, modify the value of the `dsn` in `gorm.go`:
If you are using a TiDB Cloud Serverless Tier cluster, modify the value of the `dsn` in `gorm.go`:

{{< copyable "" >}}

```go
dsn := "root:@tcp(127.0.0.1:4000)/test?charset=utf8mb4"
```

Suppose that the password you set is `123456` and the connection string you get from TiDB Cloud is the following:
Suppose that the password you set is `123456`, and the connection parameters you get from the cluster details page are the following:

```
mysql --connect-timeout 15 -u root -h xxx.tidbcloud.com -P 4000 -p
```
- Endpoint: `xxx.tidbcloud.com`
- Port: `4000`
- User: `2aEp24QWEDLqRFs.root`

In this case, you can modify the parameters as follows:
In this case, you can modify the `mysql.RegisterTLSConfig` and `dsn` as follows:

{{< copyable "" >}}

```go
dsn := "root:123456@tcp(xxx.tidbcloud.com:4000)/test?charset=utf8mb4"
mysql.RegisterTLSConfig("register-tidb-tls", &tls.Config {
MinVersion: tls.VersionTLS12,
ServerName: "xxx.tidbcloud.com",
})

dsn := "2aEp24QWEDLqRFs.root:123456@tcp(xxx.tidbcloud.com:4000)/test?charset=utf8mb4&tls=register-tidb-tls"
```

</div>

<div label="Using go-sql-driver/mysql" value="sqldriver">

If you are using a non-local default cluster, such as TiDB Cloud or other remote clusters, modify the value of the `dsn` in `sqldriver.go`:

{{< copyable "" >}}
If you are using a TiDB Cloud Serverless Tier cluster, modify the value of the `dsn` in `sqldriver.go`:

```go
dsn := "root:@tcp(127.0.0.1:4000)/test?charset=utf8mb4"
```

Suppose that the password you set is `123456` and the connection string you get from TiDB Cloud is the following:
Suppose that the password you set is `123456`, and the connection parameters you get from the cluster details page are the following:

```
mysql --connect-timeout 15 -u root -h xxx.tidbcloud.com -P 4000 -p
```
- Endpoint: `xxx.tidbcloud.com`
- Port: `4000`
- User: `2aEp24QWEDLqRFs.root`

In this case, you can modify the parameters as follows:
In this case, you can modify the `mysql.RegisterTLSConfig` and `dsn` as follows:

{{< copyable "" >}}

```go
dsn := "root:123456@tcp(xxx.tidbcloud.com:4000)/test?charset=utf8mb4"
mysql.RegisterTLSConfig("register-tidb-tls", &tls.Config {
MinVersion: tls.VersionTLS12,
ServerName: "xxx.tidbcloud.com",
})

dsn := "2aEp24QWEDLqRFs.root:123456@tcp(xxx.tidbcloud.com:4000)/test?charset=utf8mb4&tls=register-tidb-tls"
```

</div>
Expand Down
46 changes: 22 additions & 24 deletions develop/dev-guide-sample-application-java.md
Original file line number Diff line number Diff line change
Expand Up @@ -1488,7 +1488,7 @@ When using JDBC, you need to connect to your cluster and run the statement in th

<div label="Using Mybatis (Recommended)" value="mybatis">

If you are using a non-local default cluster, such as TiDB Cloud or other remote cluster, modify the `dataSource.url`, `dataSource.username`, `dataSource.password` in `mybatis-config.xml`.
If you are using a TiDB Cloud Serverless Tier cluster, modify the `dataSource.url`, `dataSource.username`, `dataSource.password` in `mybatis-config.xml`.

{{< copyable "" >}}

Expand Down Expand Up @@ -1533,13 +1533,11 @@ If you are using a non-local default cluster, such as TiDB Cloud or other remote
</configuration>
```

Suppose that the password you set is `123456` and the connection string you get from TiDB Cloud is the following:
Suppose that the password you set is `123456`, and the connection parameters you get from the cluster details page are the following:

{{< copyable "shell-regular" >}}

```shell
mysql --connect-timeout 15 -u root -h xxx.tidbcloud.com -P 4000 -p
```
- Endpoint: `xxx.tidbcloud.com`
- Port: `4000`
- User: `2aEp24QWEDLqRFs.root`

In this case, you can modify the parameters in `dataSource` node as follows:

Expand All @@ -1556,8 +1554,8 @@ In this case, you can modify the parameters in `dataSource` node as follows:
<!-- Database pool -->
<dataSource type="POOLED">
<property name="driver" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://xxx.tidbcloud.com:4000/test"/>
<property name="username" value="root"/>
<property name="url" value="jdbc:mysql://xxx.tidbcloud.com:4000/test?sslMode=VERIFY_IDENTITY&amp;enabledTLSProtocols=TLSv1.2,TLSv1.3"/>
<property name="username" value="2aEp24QWEDLqRFs.root"/>
<property name="password" value="123456"/>
</dataSource>
...
Expand All @@ -1569,7 +1567,7 @@ In this case, you can modify the parameters in `dataSource` node as follows:

<div label="Using Hibernate (Recommended)" value="hibernate">

If you are using a non-local default cluster, such as TiDB Cloud or other remote cluster, modify the `hibernate.connection.url`, `hibernate.connection.username`, `hibernate.connection.password` in `hibernate.cfg.xml`.
If you are using a TiDB Cloud Serverless Tier cluster, modify the `hibernate.connection.url`, `hibernate.connection.username`, `hibernate.connection.password` in `hibernate.cfg.xml`.

{{< copyable "" >}}

Expand Down Expand Up @@ -1599,13 +1597,11 @@ If you are using a non-local default cluster, such as TiDB Cloud or other remote
</hibernate-configuration>
```

Suppose that the password you set is `123456` and the connection string you get from TiDB Cloud is the following:
Suppose that the password you set is `123456`, and the connection parameters you get from the cluster details page are the following:

{{< copyable "shell-regular" >}}

```shell
mysql --connect-timeout 15 -u root -h xxx.tidbcloud.com -P 4000 -p
```
- Endpoint: `xxx.tidbcloud.com`
- Port: `4000`
- User: `2aEp24QWEDLqRFs.root`

In this case, you can modify the parameters as follows:

Expand All @@ -1622,8 +1618,8 @@ In this case, you can modify the parameters as follows:
<!-- Database connection settings -->
<property name="hibernate.connection.driver_class">com.mysql.cj.jdbc.Driver</property>
<property name="hibernate.dialect">org.hibernate.dialect.TiDBDialect</property>
<property name="hibernate.connection.url">jdbc:mysql://xxx.tidbcloud.com:4000/test</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.url">jdbc:mysql://xxx.tidbcloud.com:4000/test?sslMode=VERIFY_IDENTITY&amp;enabledTLSProtocols=TLSv1.2,TLSv1.3</property>
<property name="hibernate.connection.username">2aEp24QWEDLqRFs.root</property>
<property name="hibernate.connection.password">123456</property>
<property name="hibernate.connection.autocommit">false</property>

Expand All @@ -1641,7 +1637,7 @@ In this case, you can modify the parameters as follows:

<div label="Using JDBC" value="jdbc">

If you are using a non-local default cluster, such as TiDB Cloud or other remote clusters, modify the parameters of the host, port, user, and password in `JDBCExample.java`:
If you are using a TiDB Cloud Serverless Tier cluster, modify the parameters of the host, port, user, and password in `JDBCExample.java`:

{{< copyable "" >}}

Expand All @@ -1653,11 +1649,11 @@ mysqlDataSource.setUser("root");
mysqlDataSource.setPassword("");
```

Suppose that the password you set is `123456` and the connection string you get from TiDB Cloud is the following:
Suppose that the password you set is `123456`, and the connection parameters you get from the cluster details page are the following:

```
mysql --connect-timeout 15 -u root -h xxx.tidbcloud.com -P 4000 -p
```
- Endpoint: `xxx.tidbcloud.com`
- Port: `4000`
- User: `2aEp24QWEDLqRFs.root`

In this case, you can modify the parameters as follows:

Expand All @@ -1667,8 +1663,10 @@ In this case, you can modify the parameters as follows:
mysqlDataSource.setServerName("xxx.tidbcloud.com");
mysqlDataSource.setPortNumber(4000);
mysqlDataSource.setDatabaseName("test");
mysqlDataSource.setUser("root");
mysqlDataSource.setUser("2aEp24QWEDLqRFs.root");
mysqlDataSource.setPassword("123456");
mysqlDataSource.setSslMode(PropertyDefinitions.SslMode.VERIFY_IDENTITY.name());
mysqlDataSource.setEnabledTLSProtocols("TLSv1.2,TLSv1.3");
```

</div>
Expand Down
16 changes: 7 additions & 9 deletions develop/dev-guide-sample-application-spring-boot.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ If you want to learn more about the code of this application, refer to [Implemen

### Step 5.1 Change parameters

If you use a non-local default cluster, a TiDB Cloud cluster or a remote cluster, change the `spring.datasource.url`, `spring.datasource.username`, `spring.datasource.password` parameters in the `application.yml` (located in `src/main/resources`).
If you are using a TiDB Cloud Serverless Tier cluster, change the `spring.datasource.url`, `spring.datasource.username`, `spring.datasource.password` parameters in the `application.yml` (located in `src/main/resources`).

{{< copyable "" >}}

Expand All @@ -206,13 +206,11 @@ spring:
ddl-auto: create-drop
```

If you set the password to `123456`, the connection string you get in TiDB Cloud is as follows:
Suppose that the password you set is `123456`, and the connection parameters you get from the cluster details page are the following:

{{< copyable "shell-regular" >}}

```shell
mysql --connect-timeout 15 -u root -h xxx.tidbcloud.com -P 4000 -p
```
- Endpoint: `xxx.tidbcloud.com`
- Port: `4000`
- User: `2aEp24QWEDLqRFs.root`

Accordingly, the parameters must be set as folows:

Expand All @@ -221,8 +219,8 @@ Accordingly, the parameters must be set as folows:
```yaml
spring:
datasource:
url: jdbc:mysql://xxx.tidbcloud.com:4000/test
username: root
url: jdbc:mysql://xxx.tidbcloud.com:4000/test?sslMode=VERIFY_IDENTITY&enabledTLSProtocols=TLSv1.2,TLSv1.3
username: 2aEp24QWEDLqRFs.root
password: 123456
driver-class-name: com.mysql.cj.jdbc.Driver
jpa:
Expand Down