Java连接到来自Appengine Managed VM的Cloud SQL 2nd Gen [英] Java connect to Cloud SQL 2nd Gen from Appengine Managed VM
问题描述
我得到了:
FROM gcr.io/google_appengine/java-compat
)
/ cloudsql / **
socket),但默认MySQL Java驱动程序不支持unix套接字
java.lang.ClassNotFoundException:com.mysql.jdbc.GoogleDriver
)
找不到合适的驱动程序
为 jdbc:google:mysql:// __ IP__:3306 / __ db__
jdbc:mysql:// __ IP__:3306 / __ db__
(我已经将MVM外部IP添加到MySQL上的授权网络中)但是有趣的是,从MVM机器连接到此端口,至少打开端口。无论如何,我不喜欢通过公开的IP:PORT连接的想法。 MVM每次都有一个新的IP,因此我甚至不能添加防火墙规则来指定从我的项目访问
我应该如何配置ManagedVM应用程序以连接到Cloud SQL?
新的Java库,用于从托管虚拟机和其他环境连接到云SQL实例:
https://github.com/GoogleCloudPlatform/cloud-sql-mysql-socket-factory
它仍然非常新,所以通常的注意事项适用,但我们在测试中没有发现任何问题。
Trying to setup connection to Clond SQL 2nd Generation for a Java Appengine with Managed VM.
What I got:
- VM is using Appengine Compat mode (
FROM gcr.io/google_appengine/java-compat
) - I see a MySQL pipe on the host (SSHed, I can see
/cloudsql/**
socket), but default MySQL Java driver doesnt support unix sockets - Google Driver seems to be unsupported on Managed VM (
java.lang.ClassNotFoundException: com.mysql.jdbc.GoogleDriver
) - and I cannot connect to MySQL by IP
- w/o driver it's
No suitable driver found
forjdbc:google:mysql://__IP__:3306/__db__
- or timeout for
jdbc:mysql://__IP__:3306/__db__
(I've added MVM external IP to authorized networks on MySQL) - but what interesting, I can connect to this port from MVM machine, at least port is opened. Anyway, I don't like idea of connecting through publicly open IP:PORT. MVM have a new IP each time, so I even can't add a Firewall rule to specify access from my project only
- w/o driver it's
How I should configure ManagedVM app to connect to Cloud SQL?
We have a new Java library for connecting to Cloud SQL instances from Managed VMs and other environments: https://github.com/GoogleCloudPlatform/cloud-sql-mysql-socket-factory
It's still very new so the usual caveats apply, but we haven't found any issues in our testing.
这篇关于Java连接到来自Appengine Managed VM的Cloud SQL 2nd Gen的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!