can't connect to MySQL with GCP VM Instance docker ERROR 2002 (HY000)

775 Views Asked by At

I have a VM instance booting on container optimised OS and with the following Startup script:

docker pull gcr.io/cloudsql-docker/gce-proxy:1.16

docker run -d \
  -p 0.0.0.0:3306:3306 \
  gcr.io/cloudsql-docker/gce-proxy:1.16 /cloud_sql_proxy \
  -instances=<cloudsql-connection-name>=tcp:0.0.0.0:3306

When trying to connect to the db running the following command from the cloud shell mysql -ppass -u root I have the following error:

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

What does this mean? What should I do?

The context is that I need to use this vm mysql proxy to connect data fusion.

1

There are 1 best solutions below

2
On

Add this command line option to connect via TCP:

-h 127.0.0.1

Example:

mysql -h 127.0.0.1 -ppass -u root

Note: You are specifying an older version of the Cloud SQL Auth Proxy container.

https://console.cloud.google.com/gcr/images/cloudsql-docker/GLOBAL/gce-proxy