Connect to TiDB with JetBrains DataGrip
TiDB is a MySQL-compatible database, and JetBrains DataGrip is a powerful integrated development environment (IDE) for database and SQL. This tutorial walks you through the process of connecting to your TiDB cluster using DataGrip.
You can use DataGrip in two ways:
- As the DataGrip IDE standalone tool.
- As the Database Tools and SQL plugin in JetBrains IDEs, such as IntelliJ, PhpStorm, and PyCharm.
This tutorial mainly focuses on the standalone DataGrip IDE. The steps of connecting to TiDB using the JetBrains Database Tools and SQL plugin in JetBrains IDEs are similar. You can also follow the steps in this document for reference when connecting to TiDB from any JetBrains IDE.
Prerequisites
To complete this tutorial, you need:
- DataGrip 2023.2.1 or later or a non-community edition JetBrains IDE.
- A TiDB cluster.
If you don't have a TiDB cluster, you can create one as follows:
- (Recommended) Follow Creating a TiDB Cloud Serverless cluster to create your own TiDB Cloud cluster.
- Follow Deploy a local test TiDB cluster or Deploy a production TiDB cluster to create a local cluster.
Connect to TiDB
Connect to your TiDB cluster depending on the TiDB deployment option you've selected.
- TiDB Cloud Serverless
- TiDB Cloud Dedicated
- TiDB Self-Managed
Navigate to the Clusters page, and then click the name of your target cluster to go to its overview page.
Click Connect in the upper-right corner. A connection dialog is displayed.
Ensure the configurations in the connection dialog match your operating environment.
- Connection Type is set to
Public
- Branch is set to
main
- Connect With is set to
DataGrip
- Operating System matches your environment.
- Connection Type is set to
Click Generate Password to create a random password.
Launch DataGrip and create a project to manage your connections.
In the newly created project, click + in the upper-left corner of the Database Explorer panel, and select Data Source > Other > TiDB.
Copy the connection string from the TiDB Cloud connection dialog. Then, paste it into the URL field, and the remaining parameters will be auto-populated. An example result is as follows:
If a Download missing driver files warning displays, click Download to acquire the driver files.
Click Test Connection to validate the connection to the TiDB Cloud Serverless cluster.
Click OK to save the connection configuration.
Navigate to the Clusters page, and then click the name of your target cluster to go to its overview page.
Click Connect in the upper-right corner. A connection dialog is displayed.
In the connection dialog, select Public from the Connection Type drop-down list, and then click CA cert to download the CA certificate.
If you have not configured the IP access list, click Configure IP Access List or follow the steps in Configure an IP Access List to configure it before your first connection.
In addition to the Public connection type, TiDB Dedicated supports Private Endpoint and VPC Peering connection types. For more information, see Connect to Your TiDB Dedicated Cluster.
Launch DataGrip and create a project to manage your connections.
In the newly created project, click + in the upper-left corner of the Database Explorer panel, and select Data Source > Other > TiDB.
Copy and paste the appropriate connection string into the Data Source and Drivers window in DataGrip. The mappings between DataGrip fields and TiDB Cloud Dedicated connection string are as follows:
DataGrip field TiDB Cloud Dedicated connection string Host {host}
Port {port}
User {user}
Password {password}
An example is as follows:
Click the SSH/SSL tab, select the Use SSL checkbox, and input the CA certificate path into the CA file field.
If a Download missing driver files warning displays, click Download to acquire the driver files.
Click the Advanced tab, scroll to find the enabledTLSProtocols parameter, and set its value to
TLSv1.2,TLSv1.3
.Click Test Connection to validate the connection to the TiDB Cloud Dedicated cluster.
Click OK to save the connection configuration.
Launch DataGrip and create a project to manage your connections.
In the newly created project, click + in the upper-left corner of the Database Explorer panel, and select Data Source > Other > TiDB.
Configure the following connection parameters:
- Host: The IP address or domain name of your TiDB Self-Managed cluster.
- Port: The port number of your TiDB Self-Managed cluster.
- User: The username to use to connect to your TiDB Self-Managed cluster.
- Password: The password of the username.
An example is as follows:
If a Download missing driver files warning displays, click Download to acquire the driver files.
Click Test Connection to validate the connection to the TiDB Self-Managed cluster.
Click OK to save the connection configuration.
Next steps
- Learn more usage of DataGrip from the documentation of DataGrip.
- Learn the best practices for TiDB application development with the chapters in the Developer guide, such as Insert data, Update data, Delete data, Single table reading, Transactions, and SQL performance optimization.
- Learn through the professional TiDB developer courses and earn TiDB certifications after passing the exam.
Need help?
Ask the community on Discord or Slack, or submit a support ticket.