Connect to a Cloud SQL database

Cloud Code supports running Cloud SQL Auth proxy to connect to a Cloud SQL database, viewing Cloud SQL instances, and creating new data sources.

Before you begin

Connect to Cloud SQL database using Cloud SQL Auth proxy

You can connect to a Cloud SQL database and view a list of Cloud SQL instances in IntelliJ or other supported JetBrains IDEs with Cloud Code.

To connect to a Cloud SQL database with Cloud Code, perform the following:

  1. In your IDE, click Google Cloud Databases in the sidebar or click View > Tool Windows > Google Cloud Databases.

  2. If a Google Cloud project isn't already selected, click Select a Google Cloud project and follow the prompts to load your Google Cloud project.

    Cloud SQL instances in your Google Cloud project appear under Cloud SQL.

    Cloud SQL tools window

  3. To connect to a Cloud SQL instance, right-click an instance and select Connect using Cloud SQL Proxy. You can also choose to use a private IP by selecting Connect using Cloud SQL Proxy (Private IP).

To learn more about connecting to SQL instances, see About connection options.

Create a new data source

After a Cloud SQL Auth proxy connection is established, the Cloud SQL Instance Connected dialog appears, giving you the option to create a new data source for the locally available database or view existing data sources.

  1. To create a new data source, select Create new data source.

    Alternatively, you can right-click an instance and select Create New Data Source.

    Data Sources and Drivers dialog

  2. In the Authentication field, select a method (by default, this is a username and password).

  3. Save the configuration.

    Cloud Code creates a new data source connection with a name in the following format:

    gcp-project:location:db-instance-name.

    You can begin working with the database instance via JetBrains' Database Tools and SQL plugin capabilities, or DataGrip.

  4. (Optional) To view the list of data sources in your IDE, click Database in the Sidebar or View > Tool Windows > Database. Right-clicking a data source provides you with a list of options, such as viewing schemas, tables, and other database operations.

    Database tools options

    To learn more about working with databases in DataGrip, see Quick start with DataGrip.

Disconnect Cloud SQL Auth proxy

To stop the proxy process and free up the local database port, in the terminal, press Ctrl+C.

Known issues

This section lists any known issues and their current resolutions.

Set a different port to connect to several databases

The Cloud SQL Auth proxy doesn't auto-select ports if busy and always depends on one, which limits you to a single connected instance of a certain type of database.

Cloud Code runs Cloud SQL Auth proxy in the terminal, and if it runs into a port conflict, you can set a different port to connect to a database by running the same command in the terminal with a custom --port flag. For example:

--port=PORT_NUMBER

You can then use this port in your database connection. The command will be auto-generated. For example:

path_to_proxy/cloud-sql-proxy INSTANCE_CONNECTION_STRING

Get support

To submit feedback or report an issue in your IntelliJ IDE, go to Tools > Cloud Code > Help / About > Submit feedback or report an issue to report an issue on GitHub, or ask a question on Stack Overflow.