Matt
Matt

Reputation: 43

Communications link failure when connect to Google Cloud SQL(second gen) only from prod

Setting up a google cloud platform app with google cloud sql and for the life of me I cannot get a connection to the db when I run the code from google servers.

Following this example: https://cloud.google.com/appengine/docs/java/cloud-sql/?csw=1 I've gotten the non production url constructed properly and can connect with no issues to the cloud sql with this url

Class.forName("com.mysql.jdbc.Driver");
url = "jdbc:mysql://<ip-address>:3306/<database>?user=root";

So that's all good. This is the url I'm building for the prod connection.

Class.forName("com.mysql.jdbc.GoogleDriver");
url = "jdbc:google:mysql://<project-id>:<cloud sql instance name>/<database>?user=root";

I got the Project ID from the dashboard and the Instance ID SQL Instances List, database is the same as the non prod value and since non prod works I'm confident that's alright

Product and Instance ID locations I pulled them from

After deploying it all out I get the error message:

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.

appengine-web.xml does have use-google-connector-j set to true and I saw that for the second generation cloud sql you do not need to specify your app on the authorization list in cloud SQL.

Any help would be appreciated

Upvotes: 4

Views: 5069

Answers (2)

user979222
user979222

Reputation:

When trying to connect to GCP SQL from google cloud run, do not forget to enable connection to GCP SQL from the google cloud run service level settings.

Having the setting disabled (default) can also cause the communications link faulure error.

Upvotes: 0

Herman
Herman

Reputation: 2072

https://cloud.google.com/sql/docs/dev-access#gaev1-csqlv2-connect

You should look at "instance connection name" in "Instance details" of your instance. For second generation, it's "project-id:region-name:cloud-sql-instance-name", not "project-id:cloud-sql-instance-name" as in the first generation.

Upvotes: 2

Related Questions