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.

JetBrains DataGrip - 图1

Note

This tutorial is compatible with TiDB Serverless, TiDB Dedicated, and TiDB Self-Hosted.

You can use DataGrip in two ways:

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:

If you don’t have a TiDB cluster, you can create one as follows:

If you don’t have a TiDB cluster, you can create one as follows:

Connect to TiDB

Connect to your TiDB cluster depending on the TiDB deployment option you’ve selected.

  • TiDB Serverless
  • TiDB Dedicated
  • TiDB Self-Hosted
  1. Navigate to the Clusters page, and then click the name of your target cluster to go to its overview page.

  2. Click Connect in the upper-right corner. A connection dialog is displayed.

  3. Ensure the configurations in the connection dialog match your operating environment.

    • Endpoint Type is set to Public
    • Branch is set to main
    • Connect With is set to DataGrip
    • Operating System matches your environment.
  4. Click Generate Password to create a random password.

    JetBrains DataGrip - 图2

    Tip

    If you have created a password before, you can either use the original password or click Reset Password to generate a new one.

  5. Launch DataGrip and create a project to manage your connections.

    Create a project in DataGrip

  6. In the newly created project, click + in the upper-left corner of the Database Explorer panel, and select Data Source > Other > TiDB.

    Select a data source in DataGrip

  7. 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:

    Configure the URL field for TiDB Serverless

    If a Download missing driver files warning displays, click Download to acquire the driver files.

  8. Click Test Connection to validate the connection to the TiDB Serverless cluster.

    Test the connection to a TiDB Serverless clustser

  9. Click OK to save the connection configuration.

  10. Navigate to the Clusters page, and then click the name of your target cluster to go to its overview page.

  11. Click Connect in the upper-right corner. A connection dialog is displayed.

  12. Click Allow Access from Anywhere and then click Download CA cert to download the CA certificate.

    For more details about how to obtain the connection string, refer to TiDB Dedicated standard connection.

  13. Launch DataGrip and create a project to manage your connections.

    Create a project in DataGrip

  14. In the newly created project, click + in the upper-left corner of the Database Explorer panel, and select Data Source > Other > TiDB.

    Select a data source in DataGrip

  15. Copy and paste the appropriate connection string into the Data Source and Drivers window in DataGrip. The mappings between DataGrip fields and TiDB Dedicated connection string are as follows:

    DataGrip fieldTiDB Dedicated connection string
    Host{host}
    Port{port}
    User{user}
    Password{password}

    An example is as follows:

    Configure the connection parameters for TiDB Dedicated

  16. Click the SSH/SSL tab, select the Use SSL checkbox, and input the CA certificate path into the CA file field.

    Configure the CA for TiDB Dedicated

    If a Download missing driver files warning displays, click Download to acquire the driver files.

  17. Click the Advanced tab, scroll to find the enabledTLSProtocols parameter, and set its value to TLSv1.2,TLSv1.3.

    Configure the TLS for TiDB Dedicated

  18. Click Test Connection to validate the connection to the TiDB Dedicated cluster.

    Test the connection to a TiDB Dedicated cluster

  19. Click OK to save the connection configuration.

  20. Launch DataGrip and create a project to manage your connections.

    Create a project in DataGrip

  21. In the newly created project, click + in the upper-left corner of the Database Explorer panel, and select Data Source > Other > TiDB.

    Select a data source in DataGrip

  22. Configure the following connection parameters:

    • Host: The IP address or domain name of your TiDB Self-Hosted cluster.
    • Port: The port number of your TiDB Self-Hosted cluster.
    • User: The username to use to connect to your TiDB Self-Hosted cluster.
    • Password: The password of the username.

    An example is as follows:

    Configure the connection parameters for TiDB Self-Hosted

    If a Download missing driver files warning displays, click Download to acquire the driver files.

  23. Click Test Connection to validate the connection to the TiDB Self-Hosted cluster.

    Test the connection to a TiDB Self-Hosted cluster

  24. Click OK to save the connection configuration.

Next steps

Need help?

Ask questions on the Discord, or create a support ticket.