Search code examples
mysqljdbcgoogle-cloud-sql

Unable to connect to cloud sql on GCP


I am trying to connect to cloud sql hosted in gcp from eclipse, not able to do so. I have whitelisted my ip using the connection settings on cloud sql instance. I have added the driver also in eclipse for mysql.

I think I am making mistake in constructing the connection string. Please refer below details.

connectionName: abc-dev:europe-west1:abc-instance

So in connection section

database: abc-dev:europe-west1:abc-instance
url: jdbc:mysql://35.233.100.100:3306/abcInsoles
user: root
password: xyz123

It throws exception: com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure

I am running it from local.

Can you throw some insights?

Many thanks.


Solution

  • The "database" value is incorrect - this is the name of the database on the instance itself (not the instance's connection string).

    Since you are using Java, you may be interested in the Cloud SQL JDBC Socket Factory - it allows you to connect to the Cloud SQL instance without whitelisting an IP.