Thursday, September 22, 2016

Re: [google-cloud-sql-discuss] How to connect from a pool of compute engine instances to Cloud SQL DB in the same project?

Went ahead with using Google Cloud Sql proxy. Now able to connect my GCE instance to the Cloud SQL DB. 

Some details captured at https://roshandawrani.wordpress.com/2016/09/22/connecting-from-gce-gae-java-to-google-cloud-sql/, just in case someone is in a similar boat and unclear a bit.

Cheers.

On Thursday, 22 September 2016 01:39:54 UTC+5:30, Roshan Dawrani wrote:
Tried with the port 3306 also, but same errors:

C) I also tried switching ""jdbc:mysql://111.222.111.222:3306/__my_db_name?cloudSqlInstance...." format (where 111.222.111.222 is my Cloud SQL DB instance's IP address), but I still get the errors:

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

Caused by: java.net.ConnectException: Connection timed out

On Thursday, 22 September 2016 01:25:08 UTC+5:30, Roshan Dawrani wrote:
Just gave it a try, but got the following errors:

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

Caused by: java.net.UnknownHostException: google: unknown error

A) My JDBC connection string looked like (as per the library's documentation on GitHub):

"jdbc:mysql://google/__my_db__name?cloudSqlInstance=__my_cloud_sql_instance_connection_name_as_foo:bar:baz&socketFactory=com.google.cloud.sql.mysql.SocketFactory"

Is the format ""jdbc:mysql://google/...." correct for a compute engine environment?

B) I also tried switching ""jdbc:mysql://111.222.111.222/__my_db_name?cloudSqlInstance...." format (where 111.222.111.222 is my Cloud SQL DB instance's IP address), but I still get the errors:

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

Caused by: java.net.ConnectException: Connection timed out

Am I doing something wrong? Both my compute engine instance and Cloud Sql DB instance are under the same project and compute engine's default service account has an Editor role too.

On Thursday, 22 September 2016 00:51:04 UTC+5:30, Vadim Berezniker wrote:
This uses the regular mysql driver so pass in the credentials in the same way you would for the regular mysql driver (either via the URL or via properties). 
This library only overrides how the connection in established to MySQL.

On Wed, Sep 21, 2016 at 12:18 PM Roshan Dawrani <roshan...@gmail.com> wrote:
Is there any reasonable documentation available for how to use it? I googled and only saw some questions, etc in conjunction with AppEngine Flexible Enviroment.

The github repo README only says that JDBC url should look like "jdbc:mysql://google/mydb?cloudSqlInstance=foo:bar:baz&socketFactory=com.google.cloud.sql.mysql.SocketFactory"

Where do I pass the login credentials for the user I am logging in as to the database server?

On Thursday, 22 September 2016 00:24:50 UTC+5:30, Vadim Berezniker wrote:
On Wed, Sep 21, 2016 at 11:48 AM Roshan Dawrani <roshan...@gmail.com> wrote:
Hi,

If I have a pool of Compute Engine instances (behind a load-balancer with a static IP), and I want to connect from Java apps on these instances to a Cloud Sql database in the same project, what's the way to about it?

1) These instances in the load balancer don't have static external IPs, so I can't authorize access to Cloud SQL by IP addresses.

2) "com.mysql.jdbc.GoogleDriver" is not available on Compute Engine, as it is on App Engine.

3) If I try to use the stock MySql JDBC driver, it doesn't understand a connection string like:

    "jdbc:google:mysql://__instance_name__/__db_name__>?user=__user__&amp;password=__password__";

    and fails saying "No suitable driver found for jdbc:google:mysql://__instance_name__/__db_name__>?user=__user__&amp;password=__password__"

I can't believe I can't easily connect from Compute Engine instances to a Cloud SQL database of the same Google Cloud project.

Is my only option to use "Connecting using the Cloud SQL Proxy" approach as described on https://cloud.google.com/sql/docs/compute-engine-access? That seems significant amount of work to be done automatically on instances that will come to the pool and go away at will!

Could someone advise please?

Thanks,
Roshan

--
You received this message because you are subscribed to the Google Groups "Google Cloud SQL discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-discuss+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-cloud-sql-discuss/dc37088f-5f15-4e10-8c9f-383cca2dece0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Google Cloud SQL discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-discuss+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-cloud-sql-discuss/9e5f50ea-0b8f-4595-aeea-7a5f34f9c1f2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Google Cloud SQL discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-discuss+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-cloud-sql-discuss/36c21146-8812-420f-86e1-3b9fe618f4c1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment