I am assuming, you have configured your Google Cloud SQL instance for your project. If yes, then continue, otherwise you need to read “Google Cloud SQL Quickstarter Guide“.
Now Download cloud_sql_proxy.linux.amd64 package in your local machine with
"sudo wget https://dl.google.com/cloudsql/cloud_sql_proxy.linux.amd64"
mv cloud_sql_proxy.linux.amd64 cloud_sql_proxy
and give execution permission by
chmod +x cloud_sql_proxy
Create application default credentials using “gcloud auth application-default login” command
Create a directory
sudo mkdir -p /cloudsql for Google Cloud SQL proxy unix socket and make that directory writable
sudo chmod 777 /cloudsql
start sql socket proxy by
./cloud_sql_proxy -dir=/cloudsql &
Now you can have working mysql DSN “mysql:unix_socket=/cloudsql/INSTANCE_CONNECTION_NAME” which you can use in your application and your application will work with Google Cloud SQL instance directly from local machine.
Please ask me anything about this post in comment below. I will be glad to assist you happily.