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
Install Cloud Code if you haven't already.
To create a new data source, you can use one of the following premium JetBrains IDEs:
IntelliJ Ultimate or another premium JetBrains IDE which contains the Database Tools and SQL plugin (enabled by default).
DataGrip, the standalone database management environment.
You can also use other preferred database tools (such as DBeaver, MySQL Workbench, and SQL Server Management Studio) to connect to the Cloud SQL instances using the local port provided by Cloud Code.
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:
In your IDE, click Google Cloud Databases in the sidebar or click View > Tool Windows > Google Cloud Databases.
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.
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.
To create a new data source, select Create new data source.
Alternatively, you can right-click an instance and select Create New Data Source.
In the Authentication field, select a method (by default, this is a username and password).
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.
(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.
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