GoogleCloudPlatform/cloud-sql-go-connector

Where does port 3307 come from?

Closed this issue · 2 comments

I am trying to set up a connection from a pod in GKE to a Cloud SQL instance with a private IP address in the same VPC. Network manager connectivity tests confirm the traffic works fine from my cluster node IP address to the Cloud SQL instance, port 5432. However when I deploy my application I get

connect failed","err":"failed to connect to `host=/tmp user=myapp database=whatever`: dial error (timeout: Dial error: failed to dial (connection name = \"whatever:europe-west3:<instance-name>\"): dial tcp <instance-private-ip>:3307: i/o timeout)

My database is a postgres database so I figure it should be trying to connect to 5432. Is there something internal to Cloud SQL that is exposing the database on 3307?

serverProxyPort = "3307"

I would include a code snippet but it is essentially identical to what is in the README of this repository.

Hi @Kidsan thanks for asking a question about the Cloud SQL Go Connector! 😄

The Cloud SQL Connector libraries (Go, Java and Python) as well as the Cloud SQL Proxy always use port 3307 when connecting to your Cloud SQL instance, regardless of engine type (Postgres, MySQL, SQL Server). This is because the client library actually connects to a server side proxy, as shown in this diagram from the About the Cloud SQL Proxy page (same concept for Connector libraries):

image

This Cloud SQL proxy server is configured to accept connections only through port 3307.

Hope this helps answer your question. Have a great day 😃

If there’s something in the docs we can do to help make this clear, I’d be curious to hear it. Otherwise hope this answers your question.