DataGrip 2025.2 Help

Connect to Google Cloud SQL instances

Within the framework of this topic, we are going to use a PostgreSQL instance on the Google Cloud Platform. But you can use the same instructions to connect to MySQL and Microsoft SQL Server instances of Google Cloud SQL.

If you have not created the instance yet, refer to Creating instances at cloud.google.com.

From DataGrip, you can connect to your instances by using the following options.

Configuring Google Cloud SDK

This configuration procedure is common for the Cloud SQL Proxy client and the Cloud SQL Connector for Java. If you plan to add your network to the list of authorized networks, you can skip this part.

To complete the connection's configuration, you need Google Cloud SDK.

Google Cloud SDK includes the gcloud utility that manages authentication and interactions with the Google Cloud Platform API. For more information about gcloud, refer to the gcloud reference at cloud.google.com.

Step 1. Installing Google Cloud SDK

For more information about the installation process, refer to the Installing Google Cloud SDK guide at cloud.google.com. This procedure provides a summary of steps from the guide.

  1. Download and extract the Google Cloud SDK archive.

  2. Run the gcloud init command to initialize the SDK. Follow the installation wizard in the command prompt.

    ./google-cloud-sdk/bin/gcloud init
    Run gcloud init to initialize the SDK:

Step 2. Register your application for the Cloud SQL Admin API

  1. Click the Enable the API button in the Enable the Cloud SQL Admin API section.

  2. Select your project in the dropdown and click Continue.

    You have to enable the Cloud SQL Admin API for each database project if you want to connect to the database in this project. For example, one project uses PostgreSQL, another project uses MySQL. You need to enable the API for both projects.

    Cloud SQL Admin API

Step 3. Configure authentication

  1. Run the following command to authenticate the gcloud tool.

    gcloud auth login

    This command obtains your credentials and stores them in ~/.config/gcloud/. Now you can run gcloud commands from your terminal, and it will find your credentials automatically.

    Authenticate the gcloud tool
  2. Run the following command to obtain credentials for the Application Default Credentials (ADC) library.

    gcloud auth application-default login

    This command obtains your credentials for the ADC library. Now, any code or SDK that is running on your computer will be able to find the credentials automatically.

    Authenticate the connection to the Cloud SQL server

Configuring connections with the Cloud SQL Proxy client

The Cloud SQL Proxy client communicates with your database through a secure tunnel. Read more about the client in About the Cloud SQL Proxy at cloud.google.com.

Step 1. Run the Cloud SQL Proxy client

  1. Download the Cloud SQL Proxy client. See installation instructions in Install the Cloud SQL Proxy client on your local machine at cloud.google.com.

  2. Start the proxy in the command prompt.

    ./cloud-sql-proxy --port 3306 <INSTANCE_CONNECTION_NAME>

    Replace the connection_name with the connection name of your instance. You can find this information on the Overview page of your instance. If the 3306 port is already in use, change it to another port (for example, 5435).

    The connection name of your instance on the Overview page

Step 2. Create a data source

  1. Ensure that the Cloud SQL Proxy client is running (see Step 1).

  2. Open data source properties by doing one of the following:

    • Navigate to File | Data Sources.

    • On the Database Explorer (⌘ 1) toolbar, click The Data Sources icon Data Sources.

    • Press Ctrl+Alt+Shift+S.

    Open the Data Source and Drivers dialog
  3. In the Data Sources and Drivers dialog, click the Add icon (The Add icon) and select your database vendor (in our case, PostgreSQL).

  4. Check if there is a Download missing driver files link at the bottom of the connection settings area. Click this link to download drivers that are required to interact with a database. For a direct download link, refer to the JetBrains JDBC drivers page.

    The Download missing driver files link

    Location for the downloaded JDBC drivers is the DataGrip configuration directory.

    You can also use your drivers for the database instead of the provided ones. For more information about connecting to a database with your driver, refer to Add a user driver to an existing connection.

    If there is no Download missing driver files link, then you already have the required drivers.

  5. From the Authentication list, select User & Password.

  6. Specify connection details.

    • Host: 127.0.0.1. You are connecting to a local machine because you use the Cloud SQL Proxy client.

    • Port: 3306, or any other port that you selected for the proxy (for example, 5435).

    • User: a user who has permission to access the database.

    • Password: password of a user.

    • Database: a database to which you want to connect.

  7. Ensure that the database connection can be established using the provided details. To do this, click the Test Connection link at the bottom of the connection details section.

    Test Connection link

    If you encounter any connection issues, refer to the Cannot connect to a database page.

  8. (Optional) By default, only the default database and schema are project and dataset are database is schema is keyspace is namespace is introspected and available to work with. If you also want to work with other databases and schemas projects and datasets databases, schemas, and shared databases databases schemas keyspaces namespaces, in the Schemas tab, select them for the introspection.

    Schemas tab of the Data Sources and Drivers dialog
  9. Click OK to create the data source.

  10. Find your new data source in Database Explorer (⌘ 1) .

    • For more information about Database Explorer, see the corresponding reference topic.

    • For more information about working with database objects in DataGrip, refer to Database objects.

    • To write and run queries, open the default query console by clicking the data source and pressing F4.

    • To view and edit data of a database object, open Data editor and viewer by double-clicking the object.

step-4-run-the-cloud-sql-proxy-client

Configuring connections with the Cloud SQL Connector for Java

Create a data source

  1. Open data source properties by doing one of the following:

    • Navigate to File | Data Sources.

    • On the Database Explorer (⌘ 1) toolbar, click The Data Sources icon Data Sources.

    • Press Ctrl+Alt+Shift+S.

    Open the Data Source and Drivers dialog
  2. In the Database Explorer (⌘ 1) , click the New icon New on the toolbar and select the database you want to create a data source for.

    The Add data source button
  3. In the Connection type list, select URL only.

  4. In the Driver list, select the driver:

    • PostgreSQL: PostgreSQL (CloudSQL Proxy)

    • MySQL: MySQL (CloudSQL Proxy)

    • Microsoft SQL Server: Microsoft SQL Server (CloudSQL Proxy)

  5. Check if there is a Download missing driver files link at the bottom of the connection settings area. Click this link to download drivers that are required to interact with a database.

    The Download missing driver files link
  6. In the URL field, paste the URL in the following format:

    • PostgreSQL:

      jdbc:postgresql:///<DATABASE_NAME>?cloudSqlInstance=<INSTANCE_CONNECTION_NAME>&user=<USER_NAME>&password=<USER_PASSWORD>
    • MySQL:

      jdbc:mysql:///<DATABASE_NAME>?cloudSqlInstance=<INSTANCE_CONNECTION_NAME>&user=<USER_NAME>&password=<USER_PASSWORD>
    • Microsoft SQL Server:

      jdbc:sqlserver://;databaseName=<DATABASE_NAME>;user=<USER_NAME>;password=<USER_PASSWORD>

    , where

    • DATABASE_NAME: the database name to which you want to connect.

    • INSTANCE_CONNECTION_NAME: the instance connection name. You can find this information on the Overview page of your instance.

      The connection name of your instance on the Overview page
    • USER_NAME: a user name that has access to the database.

    • USER_PASSWORD: a user's password.

    Note that you do not need to specify the host. Due to the properties that you set for the driver, the IP address of your instance will be detected automatically.

    Your URL might look something like this:

    • PostgreSQL:

      jdbc:postgresql:///guest?cloudSqlInstance=crucial-study-301709:us-central1:postgres&user=guest&password=guest
    • MySQL:

      jdbc:mysql:///guest?cloudSqlInstance=mysql-304410:europe-west3:mysql&user=guest&password=guest
    • Microsoft SQL Server:

      jdbc:sqlserver://;databaseName=guest;user=sqlserver;password=guest

    Alternatively, in the Connection type list, select Default and enter your connection details in the available fields.

  7. Click the Test Connection link at the bottom of the connection details area to initiate a test connection to your database.

    Test Connection link
  8. Click OK to save your new data source.

PostgreSQL data source settings

Adding your network to authorized networks

To complete this part of the guide, you need to know your external IP address or a range of IP addresses. Use the CIDR notation (for example, 192.168.100.14/24).

Step 1. Add your network to authorized networks

  1. Open a page of your Cloud SQL Instance.

  2. Select the Connections tab and click Add network.

  3. In the Network field, type your external IP address or a range of IP addresses in the CIDR notation.

  4. Click Done and then Save.

    Wait until your instance is updated.

    Add your network to authorized networks

Step 2. Create a data source

  1. Open data source properties by doing one of the following:

    • Navigate to File | Data Sources.

    • On the Database Explorer (⌘ 1) toolbar, click The Data Sources icon Data Sources.

    • Press Ctrl+Alt+Shift+S.

    Open the Data Source and Drivers dialog
  2. In the Data Sources and Drivers dialog, click the Add icon (The Add icon) and select your database vendor (for example, PostgreSQL).

  3. Check if there is a Download missing driver files link at the bottom of the connection settings area. Click this link to download drivers that are required to interact with a database. For a direct download link, refer to the JetBrains JDBC drivers page.

    The Download missing driver files link

    Location for the downloaded JDBC drivers is the DataGrip configuration directory.

    You can also use your drivers for the database instead of the provided ones. For more information about connecting to a database with your driver, refer to Add a user driver to an existing connection.

    If there is no Download missing driver files link, then you already have the required drivers.

  4. In the Host field, type the IP address of your PostgreSQL instance. You can find this IP address on the overview page of your instance.

    IP address of your PostgreSQL instance
  5. From the Authentication list, select User & Password.

  6. In the User field, type the user name that has access to the database.

  7. In the Password field, type the user's password.

  8. In the Database field, type the database name to which you want to connect.

  9. Ensure that the database connection can be established using the provided details. To do this, click the Test Connection link at the bottom of the connection details section.

    Test Connection link

    If you encounter any connection issues, refer to the Cannot connect to a database page.

  10. (Optional) By default, only the default database and schema are project and dataset are database is schema is keyspace is namespace is introspected and available to work with. If you also want to work with other databases and schemas projects and datasets databases, schemas, and shared databases databases schemas keyspaces namespaces, in the Schemas tab, select them for the introspection.

    Schemas tab of the Data Sources and Drivers dialog
  11. Click OK to create the data source.

  12. Find your new data source in Database Explorer (⌘ 1) .

    • For more information about Database Explorer, see the corresponding reference topic.

    • For more information about working with database objects in DataGrip, refer to Database objects.

    • To write and run queries, open the default query console by clicking the data source and pressing F4.

    • To view and edit data of a database object, open Data editor and viewer by double-clicking the object.

Connect to Cloud SQL with an authorized network
07 August 2025