Skip to content

Install Cloud SQL Proxy and connect to MySQL db in Ubuntu

In this post let’s see how to install cloud sql proxy and connect to a mysql database setup in Google Cloud Engine Kubernetes cluster. You should have setup gcloud in your local system before doing this.

Install cloud sql proxy

Get the latest version of cloud sql proxy from here and run the following command.

$ sudo wget https://storage.googleapis.com/cloudsql-proxy/v1.21.0/cloud_sql_proxy.linux.amd64 -O cloud_sql_proxy
Advertisements

Output

--2021-04-07 10:56:06--  https://storage.googleapis.com/cloudsql-proxy/v1.21.0/cloud_sql_proxy.linux.amd64
Resolving storage.googleapis.com (storage.googleapis.com)... 2404:6800:4007:80c::2010, 2404:6800:4007:80f::2010, 2404:6800:4007:82a::2010, ...
Connecting to storage.googleapis.com (storage.googleapis.com)|2404:6800:4007:80c::2010|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 15668281 (15M) [application/octet-stream]
Saving to: 'cloud_sql_proxy'

cloud_sql_proxy                                    100%[================================================================================================================>]  14.94M   351KB/s    in 98s     

2021-04-07 10:57:45 (156 KB/s) - 'cloud_sql_proxy' saved [15668281/15668281]
Advertisements

Give necessary permissions

$ sudo chmod +x cloud_sql_proxy

Run cloud sql proxy

$ ./cloud_sql_proxy -instances=<your-mysql-instance-name>=tcp:3306


Output

2021/04/07 10:59:26 Rlimits for file descriptors set to {Current = 8500, Max = 1048576}
2021/04/07 10:59:36 Listening on 127.0.0.1:3306 for retina-dev:us-central1:retina-mysql-instance
2021/04/07 10:59:36 Ready for new connections
Advertisements

Now you can connect to your cloud mysql database in your local system using any mysql client.

See also  How to copy files into pods using kubectl?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.