You can use the SQL Server command-line client to connect to Cloud SQL. This page describes how to connect a SQL Server client, whether running locally on your client machine or on a Compute Engine VM, to your Cloud SQL instance.
Before you begin
Before you can use a sqlcmd
client to connect to your Cloud SQL
instance, do the following:
-
Create a Cloud SQL instance, including configuring the default user.
See Create instances and Set the password for the default user account.
Optionally, create a Compute Engine VM instance and then connected to the instance using SSH.
See Create and start a VM instance, About SSH connections, or Connect to Windows VMs using RDP.
Determine how you'll connect to your instance.
For the connection options and how to choose from among them, see About connection options.
- Install the SQL Server command-line tools.
Use a SQL Server client on a local machine or a Compute Engine VM
Using a sqlcmd
client to connect to your Cloud SQL
instance involves three high-level tasks:
- Install the client.
- Configure access to your Cloud SQL instance.
- Connect to your Cloud SQL instance.
Install the client
To install the sqlcmd
client, do the following:
Debian/Ubuntu
For Debian/Ubuntu, install the applicable SQL Server command-line tools.
CentOS/RHEL
For CentOS/RHEL, install the applicable SQL Server command-line tools.
openSUSE
For openSUSE, install the applicable SQL Server command-line tools.
Other platforms
See the landing page for installing SQL Server, as well as the SQL Server downloads page.
Configure access to your Cloud SQL instance
To configure access to your instance, do the following:
- From the client machine or Compute Engine VM instance, use What's my IP to see the IP address of the client machine.
- Copy that IP address.
-
In the Google Cloud console, go to the Cloud SQL Instances page.
- To open the Overview page of an instance, click the instance name.
- Select Connections from the SQL navigation menu.
- Select the Networking tab.
- In the Authorized networks section, click Add network and enter the IP address of the machine where the client is installed.
- Click Done. Then click Save at the bottom of the page to save your changes.
- Connect to your instance.
Connect to your Cloud SQL instance
To let you connect without encryption, the instance must have requireSsl
set to false
. In the Google Cloud console, the
Allow only SSL connections checkbox must be cleared.
For more information about the SSL/TLS configuration of your instance, see Configure SSL/TLS certificates.
To connect to your instance, do the following:
- Confirm that you have installed the client and configured access to your instance.
- Use the
sqlcmd
command to connect, by following steps similar to those in the examples on the SQL Server quickstart and Use the utility pages.
Connect to your Cloud SQL instance using SSL/TLS
Use the instructions in the Client Initiated Encryption section, and related sections, of the Encrypting Connections to SQL Server on Linux page.
What's next
- Learn about configuring an instance with a private IP address.
- Learn more about SQL Server.
Try it for yourself
If you're new to Google Cloud, create an account to evaluate how Cloud SQL performs in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
Try Cloud SQL free