This page shows you how to create and connect to a SQL Server instance using a private IP. The resources created in this quickstart typically cost less than a dollar, assuming you complete the steps, including the clean up, in a timely manner.
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
roles/resourcemanager.projectCreator), which contains the
resourcemanager.projects.create permission. Learn how to grant
roles.
Verify that billing is enabled for your Google Cloud project.
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
roles/resourcemanager.projectCreator), which contains the
resourcemanager.projects.create permission. Learn how to grant
roles.
Verify that billing is enabled for your Google Cloud project.
In the Google Cloud console, go to the APIs page.
Enable the Cloud SQL Admin API. By enabling this API, you can run the Cloud SQL Auth Proxy.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.
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:
To get the permissions that you need to set up Cloud SQL with a private IP address, ask your administrator to grant you the following IAM roles on the project that you want to set up and connect to:
roles/cloudsql.admin).
roles/iam.serviceAccountAdmin).
roles/compute.admin)roles/compute.instanceAdmin.v1).
roles/servicenetworking.networksAdmin))roles/serviceusage.serviceUsageAdmin).
For more information about granting roles, see Manage access to projects, folders, and organizations.
You might also be able to get the required permissions through custom roles or other predefined roles.
There are many ways to connect to a Cloud SQL instance with a private IP address, depending on where the source is located. The key factor is that the source machine must be in the same VPC network as the Cloud SQL instance. If the source is not in Google Cloud or not in the same Google Cloud project, then you have to configure connectivity differently than we show here.
In this quickstart, we configure connectivity through the most direct path. The source and target are in the same Google Cloud project and in the same VPC network. We create a Cloud SQL instance with a private IP address (the target) and a Compute Engine VM (the source). We use the VM to install and use the tools required to connect from the VM to the Cloud SQL instance.
Perform the following actions:
Find and save the instance's connection name for later use.
You'll use the first window to install the sqlcmd and install and start the Cloud SQL Auth Proxy. Then you'll use the second window to connect to the Cloud SQL instance by connecting to the Cloud SQL Auth Proxy.
The Cloud SQL Auth Proxy acts as a connector between the sqlcmd client and the Cloud SQL instance.
On success, the Cloud SQL Auth Proxy listens for connection requests.
On success, you see your sqlcmd prompt in this window, and a successful connection message in SSH window #1, where the Cloud SQL Auth Proxy is running.
To create an instance that uses private IP connections, do the following:
In the Google Cloud console, go to the Cloud SQL Get Started page.
0.0.0.0/0.22.16 and 124 (the number of addresses
allocated is equal to 2 to the (32 - prefix length).You're taken to the instance Overview page as the new instance is being created.
After the instance creation is complete, scroll to the Connect to
this instance section and save the instance's Connection name.
The connection name is in the format projectID:region:instanceID.
You'll use this connection name later when starting the Cloud SQL Auth Proxy.
Follow these steps to create a VM:
In the Google Cloud console, go to the VM instances page.
We use two windows in the VM. The first window is used to install the sqlcmd client and the Cloud SQL Auth Proxy, get the instance connection name, and use this name to start the proxy. The second window is used to connect to the Cloud SQL instance through the proxy.
It might take a few seconds for the prompt in the window to become available for you.
pwd to verify that you're
in the /home/$USER directory.
You'll install the sqlcmd client and the Cloud SQL Auth Proxy, and also start the Cloud SQL Auth Proxy, in this window.
You'll use this window to connect to your Cloud SQL instance.
Use SSH window #1 for this step.
Install the SQL Server command-line tools (mssql-tools) for Ubuntu using these instructions.
Use SSH window #1 for this step.
wget:
sudo apt-get install wget
wget https://storage.googleapis.com/cloud-sql-connectors/cloud-sql-proxy/v2.8.2/cloud-sql-proxy.linux.amd64 \ -O cloud-sql-proxy
chmod +x cloud-sql-proxy
Use SSH window #1 for this step.
Start the Cloud SQL Auth Proxy so you can monitor its output. Replace
INSTANCE_CONNECTION_NAME with the connection name you copied
when you created the Cloud SQL instance.
./cloud-sql-proxy --private-ip INSTANCE_CONNECTION_NAME
When the Cloud SQL Auth Proxy starts successfully, a message similar to the following appears in the SSH window:
Listening on 127.0.0.1:1433 for myInstance Ready for new connections
Use SSH window #2 for this step.
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
To avoid incurring charges to your Google Cloud account for the resources used on this page, follow these steps.
In the Google Cloud console, go to the Cloud SQL Instances page.
myinstance instance to open the Instance details page.If you're not using the APIs that were enabled as part of this quickstart, you can disable them.
In the Google Cloud console, go to the APIs page.
Select the Cloud SQL Admin API and then click the Disable API button.
In the Google Cloud console, go to the VM instances page.
Select your instance's name.
Select Delete from the More actions menu.
Based on your needs, you can learn more about creating Cloud SQL instances.
You also can learn about creating SQL Server users and databases for your Cloud SQL instance.
Additionally, you can learn about connecting to a Cloud SQL instance from other Google Cloud applications:
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2026-06-11 UTC.