Quickstart for using the proxy for local testing

This page shows you how to connect to Cloud SQL from a local test environment using the Cloud SQL Proxy. Connecting through the 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 proxy for a production environment.

Before you begin

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

Enable the Cloud SQL Admin API

Enable the API

Install and authenticate the gcloud command-line tool

  1. If you haven't already, install the gcloud command-line tool.

    See the gcloud installation instructions.

  2. Initialize the gcloud tool:

    gcloud init
  3. Authenticate the gcloud tool:

    gcloud auth login

Install the Cloud SQL Proxy client on your local machine

For installation, see Installing the Cloud SQL 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 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 proxy:

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

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

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

A message similar to the following appears:

Listening on 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, which is routed through the 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 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