Connect to Cloud SQL for MySQL using the Cloud SQL Auth Proxy
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 environment andConnect 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.- 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.
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
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.Make sure 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.
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.Make sure that billing is enabled for your Google Cloud project.
- Enable the necessary Google Cloud APIs.
Console
In the Google Cloud console, go to theAPIs page.
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.Run the
gcloud 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
Make sure that you have the following role or roles on the project: Cloud SQL Admin (
roles/cloudsql.admin
), Cloud SQL Viewer (roles/cloudsql.viewer
)Check for the roles
In the Google Cloud console, go to theIAM page.
Go to IAM- Select the project.
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.
- 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
In the Google Cloud console, go to theIAM page.
Go to IAM- Select the project.
- Click Grant access.
In theNew principals field, enter your user identifier. This is typically the email address for a Google Account.
- In theSelect a role list, select a role.
- To grant additional roles, click Add another role and add each additional role.
- ClickSave.
Create a Cloud SQL instance
In this quickstart, you use the Google Cloud console. To use thegcloud CLI, cURL, or PowerShell, seeCreate instances.
In the Google Cloud console, go to theCloud SQL Instances page.
- ClickCreate instance.
- ClickChoose MySQL.
- In theInstance ID field, enter
myinstance
. - In thePassword field, enter a password for the
root
user. 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.
- Download the MySQL Community Server for your platform from theMySQL Community Server download page.
The Community Server includes the MySQL client. - Install the Community Server, following the directions on the download page.
For more information about installing MySQL, seeInstalling and Upgrading MySQL.
Install the Cloud SQL Auth Proxy client
The Cloud SQL Auth Proxy binary you download depends on your operating system, and whetherit uses a 32-bit or 64-bit kernel.Most newer hardware uses a 64-bit kernel. If you're unsure whether your machineis running a 32-bit or 64-bit kernel, then use theuname -a
commandfor Linux or macOS. For Windows, see theWindows documentation.
Linux 64-bit
- Download the Cloud SQL Auth Proxy:
curl-ocloud-sql-proxyhttps://storage.googleapis.com/cloud-sql-connectors/cloud-sql-proxy/v2.18.0/cloud-sql-proxy.linux.amd64
- Make the Cloud SQL Auth Proxy executable:
chmod+xcloud-sql-proxy
Linux 32-bit
- Download the Cloud SQL Auth Proxy:
curl-ocloud-sql-proxyhttps://storage.googleapis.com/cloud-sql-connectors/cloud-sql-proxy/v2.18.0/cloud-sql-proxy.linux.386
- If the
curl
command is not found, runsudo apt install curl
and repeat the download command. - Make the Cloud SQL Auth Proxy executable:
chmod+xcloud-sql-proxy
macOS 64-bit
- Download the Cloud SQL Auth Proxy:
curl-ocloud-sql-proxyhttps://storage.googleapis.com/cloud-sql-connectors/cloud-sql-proxy/v2.18.0/cloud-sql-proxy.darwin.amd64
- Make the Cloud SQL Auth Proxy executable:
chmod+xcloud-sql-proxy
Mac M1
- Download the Cloud SQL Auth Proxy:
curl-ocloud-sql-proxyhttps://storage.googleapis.com/cloud-sql-connectors/cloud-sql-proxy/v2.18.0/cloud-sql-proxy.darwin.arm64
- Make the Cloud SQL Auth Proxy executable:
chmod+xcloud-sql-proxy
Windows 64-bit
Right-clickhttps://storage.googleapis.com/cloud-sql-connectors/cloud-sql-proxy/v2.18.0/cloud-sql-proxy.x64.exe and selectSave Link As to download the Cloud SQL Auth Proxy. Rename the file tocloud-sql-proxy.exe
.Windows 32-bit
Right-clickhttps://storage.googleapis.com/cloud-sql-connectors/cloud-sql-proxy/v2.18.0/cloud-sql-proxy.x86.exe and selectSave Link As to download the Cloud SQL Auth Proxy. Rename the file tocloud-sql-proxy.exe
.Cloud SQL Auth Proxy Docker image
The Cloud SQL Auth Proxy has different container images, such asdistroless
,alpine
,andbuster
. The default Cloud SQL Auth Proxy container image usesdistroless
, whichcontains no shell. If you need a shell or related tools, then download an image based onalpine
orbuster
.For more information, seeCloud SQL Auth Proxy Container Images.
You can pull the latest image to your local machine using Docker by using the following command:
docker pull gcr.io/cloud-sql-connectors/cloud-sql-proxy:2.18.0
Note: The Cloud SQL Auth Proxy uses a repository that supports thegcr.io
domain but serves images from Artifact Registry. For more information, seeTransition from Container Registry.
Other OS
For other operating systems not included here, you cancompile the Cloud SQL Auth Proxy from source.Get the instance connection name
In the Google Cloud console, go to theCloud SQL Instances page.
- Click the instance name to open itsOverview page.
- In theConnect to this instance section, copy theConnection 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. 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:3306 forINSTANCE_CONNECTION_NAMEReady for new connections
Run the following command:
mysql-uroot-p--host127.0.0.1--port3306
At theEnter password:
prompt, enter the password of yourMySQL root user account.
Verify that the MySQL prompt appears. You have connected to your databaseusing the mysql client.
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.
In the Google Cloud console, go to theCloud SQL Instances page.
- Select the
myinstance
instance to open theInstance details page. - In the icon bar at the top of the page, clickDelete.
- 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
In the Google Cloud console, go to theAPIs page.
Select the Cloud SQL Admin API and then click theDisable API button.
What's next
See how totroubleshoot information for the Cloud SQL Auth Proxy.
Learn moreabout the Cloud SQL Auth Proxy.
- Learn moreabout other connection options.
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-07-14 UTC.