Connect to Cloud SQL for SQL Server 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. The Cloud SQL Auth proxy provides secure access to your Cloud SQL instance without the need for authorized networks or for configuring SSL. By using the Cloud SQL Auth proxy, you can connect to your Cloud SQL instance securely.

Don't use these instructions to set up the Cloud SQL Auth proxy for a production environment. Also, for more connection options for authenticating and using the proxy, see Connecting using the Cloud SQL Auth proxy.

Before you begin

  1. Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  3. Make sure that billing is enabled for your Cloud project. Learn how to check if billing is enabled on a project.

  4. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  5. Make sure that billing is enabled for your Cloud project. Learn how to check if billing is enabled on a project.

  6. Enable the necessary Google Cloud APIs.

    Console

    In the Google Cloud console, go to the APIs page.

    Go to APIs

    Enable the Cloud SQL Admin API.

    gcloud

    Click the following button to open Cloud Shell, which provides command-line access to your Google Cloud resources directly from the browser. Cloud Shell can be used to run the gcloud commands presented throughout this quickstart.

    Open Cloud Shell

    Run the gcloud services enable command as follows using Cloud Shell to enable the APIs required for this quickstart.:

    gcloud services enable sqladmin.googleapis.com

    This command enables the following APIs:

    • Cloud SQL Admin API

Create a Cloud SQL instance

In this quickstart, you use the Google Cloud console. To use the Google Cloud CLI, cURL, or PowerShell, see Create instances.

  1. In the Google Cloud console, go to the Cloud SQL Instances page.

    Go to Cloud SQL Instances

  2. Click Create Instance.
  3. Click Choose SQL Server.
  4. Enter myinstance for Instance ID.
  5. Enter a password for the sqlserver user.
  6. Click Create.

    You're returned to the instances list. You can click the new instance right away to see the details, but it won't be available for other operations until it initializes and starts.

Debian/Ubuntu

For Debian/Ubuntu, install the applicable SQL Server command-line tools using these instructions.

CentOS/RHEL

For CentOS/RHEL, install the applicable SQL Server command-line tools using these instructions.

openSUSE

For openSUSE, install the applicable SQL Server command-line tools using these instructions.

Other platforms

See the landing page for installing SQL Server, as well as the SQL Server downloads page.

Install the Cloud SQL Auth proxy client

For installation, see Installing the Cloud SQL Auth proxy.

Get the instance connection name

  1. In the Google Cloud console, go to the Cloud SQL Instances page.

    Go to Cloud SQL Instances

  2. Click the instance name to open its Overview page.
  3. In the Connect to this instance section, copy the Connection name. The connection name is in the format projectID:region:instanceID.

Start the Cloud SQL Auth proxy

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 INSTANCE_CONNECTION_NAME
Ready for new connections

Run the following command, replacing USER_NAME with your SQL Server username.

sqlcmd -S 127.0.0.1 -U USER_NAME

Return to the terminal window where you started the Cloud SQL Auth proxy. You should see a message similar to the following:

New connection for myInstance

Clean up

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

  1. In the Google Cloud console, go to the Cloud SQL Instances page.

    Go to Cloud SQL Instances

  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 your instance's name and then click Delete.

Optional cleanup steps

If you're not using the APIs that were enabled as part of this quickstart, you can disable them.

  • APIs that were enabled within this quickstart:
    • Cloud SQL Admin API
  1. In the Google Cloud console, go to the APIs page.

    Go to APIs

  2. Select the Cloud SQL Admin API and then click the Disable API button.

What's next