Search code examples
google-cloud-platformgoogle-cloud-sqlcloud-sql-proxy

Is it possible to connect to Cloud SQL Proxy via Host Compute Engine VM's Internal or External IP?


I am testing the following configuration.

  • Cloud SQL (tetsql-1) in Region X Zone A
  • A Compute Engine VM (TestVM-1) in the same Region X Zone A. OS is Centos 7
  • Compute Engine VM is running cloud SQL proxy on non default port (9090)

With the above configuration I am able to logon to testsql-1 from TestVM-1 with below command:

  `mysql -h 127.0.0.1 --port 9090 -u testuser -D testDB -p`

However I am not able use the internal IP of TestVM-1 in the above command. It gives an error.

Another observation is I am able to do telnet 127.0.0.1 9090 but when I try telnet <VM -Internal-IP> 9090 returns a connection refused error.

Does anyone know if this is expected behaviour? If this is expected, why is it so?


Solution

  • The reason that you can connect to 127.0.0.1 but you cannot connect using the VM's private IP address is that the Proxy is NOT listening on the private IP address.

    The Cloud SQL Proxy listens on the loopback adapter's internal address which is 127.0.0.1. This address only exists inside the computer.