Connect to Cloud SQL for SQL Server using the Cloud SQL Auth Proxy

MySQL  |  PostgreSQL  |  SQL Server

This page shows you how to connect to Cloud SQL from a local testenvironment using the Cloud SQL Auth Proxy. TheCloud SQL Auth Proxyprovides secure access to your Cloud SQL instance without the need forauthorized networks or for configuring SSL. By using the Cloud SQL Auth Proxy, you canconnect to your Cloud SQL instance securely.

The instructions on this page are for a test environment only and shouldn't beused for production environments. For more informationon the configuration required for production environments, seeUse the Cloud SQL Auth Proxy in a production environmentandConnect using the Cloud SQL Auth Proxy.

Before you begin

Note:The name you use for your project must be between 4 and 30 characters. When youtype the name, the form suggests a project ID, which you can edit. Theproject ID must be between 6 and 30 characters, with a lowercase letteras the first character. You can use a dash, lowercase letter, or digit for theremaining characters, but the last character cannot be a dash.
  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.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.create permission.Learn how to grant roles.
    Note: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.

    Go to project selector

  3. Verify that billing is enabled for your Google Cloud project.

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

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.create permission.Learn how to grant roles.
    Note: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.

    Go to project selector

  5. Verify that billing is enabled for your Google Cloud project.

  6. Enable the necessary Google Cloud APIs.

    Console

    In the Google Cloud console, go to theAPIs 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 thegcloud commands presented throughout this quickstart.

    Open Cloud Shell

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

    gcloudservicesenablesqladmin.googleapis.com

    This command enables the following APIs:

    • Cloud SQL Admin API
  7. Make sure that you have the following role or roles on the project: Cloud SQL Admin (roles/cloudsql.admin)

    Check for the roles

    1. In the Google Cloud console, go to theIAM page.

      Go to IAM
    2. Select the project.
    3. In thePrincipal column, find all rows that identify you or a group that you're included in. To learn which groups you're included in, contact your administrator.

    4. For all rows that specify or include you, check theRole column to see whether the list of roles includes the required roles.

    Grant the roles

    1. In the Google Cloud console, go to theIAM page.

      Go to IAM
    2. Select the project.
    3. ClickGrant access.
    4. In theNew principals field, enter your user identifier. This is typically the email address for a Google Account.

    5. In theSelect a role list, select a role.
    6. To grant additional roles, clickAdd another role and add each additional role.
    7. ClickSave.

Create a Cloud SQL instance

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

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

    Go to Cloud SQL Instances

  2. ClickCreate instance.
  3. ClickChoose SQL Server.
  4. In theInstance ID field, entermyinstance.
  5. In thePassword field, enter a password for thesqlserver user.
  6. ClickCreate instance.

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

    Note: In this example, the instance is created using default settings, including a public IP address.

Debian/Ubuntu

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

CentOS/RHEL

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

openSUSE

For openSUSE, install the applicable SQL Server command-line tools usingthese 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, seeInstalling the Cloud SQL Auth Proxy.

Get the instance connection name

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

    Go to Cloud SQL Instances

  2. Click the instance name to open itsOverview page.
  3. In theConnect to this instance section, copy theConnection name. The connection name is in the formatprojectID:region:instanceID.

Start the Cloud SQL Auth Proxy

Start the Cloud SQL Auth Proxy in its own terminal so you can monitor its output. ReplaceINSTANCE_CONNECTION_NAME with the instance connection name you copiedin the previous step.

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

./cloud-sql-proxyINSTANCE_CONNECTION_NAME

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

.\cloud-sql-proxy.exeINSTANCE_CONNECTION_NAME

A message similar to the following appears:

Listening on 127.0.0.1:1433 forINSTANCE_CONNECTION_NAMEReady for new connections

Run the following command, replacingUSER_NAME with your SQL Server username.

sqlcmd-S127.0.0.1-UUSER_NAME

Return to the terminal window where you started the Cloud SQL Auth Proxy. Youshould see a message similar to the following:

New connection formyInstance

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 theCloud SQL Instances page.

    Go to Cloud SQL Instances

  2. Select themyinstance instance to open theInstance details page.
  3. In the icon bar at the top of the page, clickDelete.
  4. In theDelete instance window, type your instance's name and then clickDelete.

Optional cleanup steps

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

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

    Go to APIs

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

What's next

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-12-15 UTC.