Quickstart for using the Cloud SQL Auth proxy

This page shows you how to connect to Cloud SQL from a local test environment using the Cloud SQL Auth proxy. Connecting through the Cloud SQL Auth proxy enables you to test an App Engine application in your local environment, or establish a secure connection for database administration.

Do not use these instructions to set up the Cloud SQL Auth proxy for a production environment. For more connection options, see Connecting using the Cloud SQL Auth proxy.

Before you begin

Before performing the steps in this quickstart, complete the following tasks:

Install the Cloud SQL Auth proxy client on your local machine

For installation, see Installing the Cloud SQL Auth proxy.

Get the instance connection name

  1. Go to the Cloud SQL Instances page in the Google Cloud Console.

    Go to the Cloud SQL Instances page

  2. Click the instance name to open its Instance details page.

  3. Under Connect to this instance, note the Instance connection name.

Start the Cloud SQL Auth proxy in its own terminal so you can monitor its output. Replace <INSTANCE_CONNECTION_NAME> with the instance connection name you copied in the previous step.

For Linux environments, use this command to launch the Cloud SQL Auth proxy:

./cloud_sql_proxy -instances=<INSTANCE_CONNECTION_NAME>=tcp:1433

In PowerShell on Windows, use this command to launch the Cloud SQL Auth proxy:

.\cloud_sql_proxy.exe -instances=<INSTANCE_CONNECTION_NAME>=tcp:1433

A message similar to the following appears:

Listening on 127.0.0.1:1433 for myproject:myregion:myinstance".
Ready for new connections

Connect to your database using the sqlcmd client

This section is optional, but is recommended for testing your connection.

If you installed and configured a sqlcmd client, you can connect to your Cloud SQL instance at the IP address 127.0.0.1, which is routed through the Cloud SQL Auth proxy's secure connection to Cloud SQL.

When you connect to the Cloud SQL instance through the SQL Server client, a message similar to the following is in the Cloud SQL Auth proxy terminal:

New connection for "myproject:us-central1:myinstance"

Then you can run queries and perform other operations.

Clean up

To avoid incurring charges to your Google Cloud account for the resources used in this quickstart, follow these steps.

  1. Go to the Cloud SQL Instances page in the Google Cloud Console.
    Go to the Cloud SQL Instances page
  2. Select the myinstance instance to open the Instance details page.
  3. In the icon bar at the top of the page, click Delete.
  4. In the Delete instance window, type myinstance, then click Delete to delete the instance.

    You cannot reuse an instance name for about 7 days after an instance is deleted.

What's next