Cloud SQL Proxy to Connect to Cloud SQL
- Create a VM to serve as your proxy instance. SSH onto the instance
- Download the Cloud SQL Proxy and make it executable:
wget https://dl.google.com/cloudsql/cloud_sql_proxy.linux.amd64 -O cloud_sql_proxy && chmod +x cloud_sql_proxy
Connection String- In order to start the proxy, you need the connection name of the Cloud SQL instance (from the instance itself)
- On the proxy VM
export SQL_CONNECTION=[SQL_CONNECTION_NAME] Activate the proxy connection to your Cloud SQL database and send the process to the background
./cloud_sql_proxy -instances=$SQL_CONNECTION=tcp:3306 &
Lookup the External IP of the Proxy VM
curl -H "Metadata-Flavor: Google" http://169.254.169.254/computeMetadata/v1/instance/network-interfaces/0/access-configs/0/external-ip && echo
Once you hit the external IP, you would configure the proxy
Property | Value |
---|---|
Username | root |
Password | [ROOT_PASSWORD] |
Database Host | 127.0.0.1 |
Summary
A proxy VM can be spun up and the cloud sql proxy executable installed on it. This is then used to connect to the Cloud SQL Instance - even if it does not have a public IP address.
Need an experienced AWS/GCP/Azure/DevSecOps Professional to help out with your Public Cloud Strategy? Set up a time with Anuj Varma.
Leave a Reply