无法从谷歌应用引擎(春季启动应用)连接到谷歌云sql(第二代)

时间:2017-11-18 05:12:33

标签: java google-app-engine spring-boot google-cloud-sql

最近一直让我发疯,希望有人能帮助我。

我一直在尝试从谷歌应用引擎(春季启动应用)连接谷歌云sql(第二代),但没有运气。我按照此页https://cloud.google.com/appengine/docs/flexible/java/using-cloud-sql上的说明获取连接字符串。可以从我的本地计算机连接到谷歌云sql。

另外,我的app引擎和google sql实例来自同一个项目。我还验证了我可以从goole app engine的cloud shell连接到google sql

我想知道哪个是正确的连接字符串。我试过这两个连接模板,但没有运气

  • " JDBC:谷歌:MySQL的:// $ {INSTANCE_CONNECTION_NAME} / $ {数据库}用户= $ {用户}&安培;密码= $ {密码}"

  • " JDBC:MySQL的://谷歌/ $ {数据库} useSSL =假安培; cloudSqlInstance = $ {INSTANCE_CONNECTION_NAME}&安培;的SocketFactory = com.google.cloud.sql.mysql.SocketFactory&安培;用户= $ {用户}&安培;密码= $ {密码}"

这是来自google cloud的日志跟踪:

017-11-17 00:20:51 default[20171117t071753]     at java.lang.Thread.run(Thread.java:748) [na:1.8.0_131]

2017-11-17 00:20:51 default [20171117t071753]引起:com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:通讯链接失败 2017-11-17 00:20:51默认[20171117t071753] 2017-11-17 00:20:51默认[20171117t071753]成功发送到服务器的最后一个数据包是0毫秒前。驱动程序未收到来自服务器的任何数据包。 2017-11-17 00:20:51默认[20171117t071753] at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)〜[na:1.8.0_131] 2017-11-17 00:20:51默认[20171117t071753] at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)〜[na:1.8.0_131] 2017-11-17 00:20:51默认[20171117t071753] at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)〜[na:1.8.0_131] 2017-11-17 00:20:51默认[20171117t071753] at java.lang.reflect.Constructor.newInstance(Constructor.java:423)〜[na:1.8.0_131] 2017-11-17 00:20:51默认[20171117t071753] at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)〜[mysql-connector-java-5.1.43.jar!/:5.1.43 ] 2017-11-17 00:20:51默认[20171117t071753] at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:989)~ [mysql-connector-java-5.1.43.jar!/:5.1.43 ] 2017-11-17 00:20:51默认[20171117t071753]在com.mysql.jdbc.MysqlIO。(MysqlIO.java:341)〜[mysql-connector-java-5.1.43.jar!/:5.1.43] 2017-11-17 00:20:51默认[20171117t071753] at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2196)~ [mysql-connector-java-5.1.43.jar!/:5.1.43 ] 2017-11-17 00:20:51默认[20171117t071753] at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2229)~ [mysql-connector-java-5.1.43.jar!/:5.1.43 ] 2017-11-17 00:20:51默认[20171117t071753] at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2024)〜[mysql-connector-java-5.1.43.jar!/:5.1.43 ] 2017-11-17 00:20:51默认[20171117t071753] at com.mysql.jdbc.ConnectionImpl。(ConnectionImpl.java:779)〜[mysql-connector-java-5.1.43.jar!/:5.1.43] 2017-11-17 00:20:51默认[20171117t071753] at com.mysql.jdbc.JDBC4Connection。(JDBC4Connection.java:47)〜[mysql-connector-java-5.1.43.jar!/:5.1.43] 2017-11-17 00:20:51默认[20171117t071753] at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)〜[na:1.8.0_131] 2017-11-17 00:20:51默认[20171117t071753] at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)〜[na:1.8.0_131] 2017-11-17 00:20:51默认[20171117t071753] at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)〜[na:1.8.0_131] 2017-11-17 00:20:51默认[20171117t071753] at java.lang.reflect.Constructor.newInstance(Constructor.java:423)〜[na:1.8.0_131] 2017-11-17 00:20:51默认[20171117t071753] at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)〜[mysql-connector-java-5.1.43.jar!/:5.1.43 ] 2017-11-17 00:20:51默认[20171117t071753] at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:389)〜[mysql-connector-java-5.1.43.jar!/:5.1.43 ] 2017-11-17 00:20:51默认[20171117t071753] at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:330)〜[mysql-connector-java-5.1.43.jar!/:5.1.43 ] 2017-11-17 00:20:51默认[20171117t071753] at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:310)〜[tomcat-jdbc-8.5.16.jar!/:na ] 2017-11-17 00:20:51默认[20171117t071753] at org.apache.tomcat.jdbc.pool.PooledConnection.connect(PooledConnection.java:203)〜[tomcat-jdbc-8.5.16.jar!/:na ] 2017-11-17 00:20:51默认[20171117t071753] at org.apache.tomcat.jdbc.pool.ConnectionPool.createConnection(ConnectionPool.java:735)〜[tomcat-jdbc-8.5.16.jar!/:na ] 2017-11-17 00:20:51默认[20171117t071753] org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:667)〜[tomcat-jdbc-8.5.16.jar!/:na ] 2017-11-17 00:20:51默认[20171117t071753] org.apache.tomcat.jdbc.pool.ConnectionPool.init(ConnectionPool.java:482)〜[tomcat-jdbc-8.5.16.jar!/:na ] 2017-11-17 00:20:51默认[20171117t071753] at org.apache.tomcat.jdbc.pool.ConnectionPool。(ConnectionPool.java:154)〜[tomcat-jdbc-8.5.16.jar!/:na] 2017-11-17 00:20:51默认[20171117t071753] at org.apache.tomcat.jdbc.pool.DataSourceProxy.pCreatePool(DataSourceProxy.java:118)~ [tomcat-jdbc-8.5.16.jar!/:na ] 2017-11-17 00:20:51默认[20171117t071753] at org.apache.tomcat.jdbc.pool.DataSourceProxy.createPool(DataSourceProxy.java:107)〜[tomcat-jdbc-8.5.16.jar!/:na ] 2017-11-17 00:20:51默认[20171117t071753] at org.apache.tomcat.jdbc.pool.DataSourceProxy.getConnection(DataSourceProxy.java:131)〜[tomcat-jdbc-8.5.16.jar!/:na ] 2017-11-17 00:20:51默认[20171117t071753] at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111)〜[spring-jdbc-4.3.10.RELEASE.jar!/:4.3 .10.RELEASE] 2017-11-17 00:20:51默认[20171117t071753] at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:77)〜[spring-jdbc-4.3.10.RELEASE.jar!/:4.3 .10.RELEASE] 2017-11-17 00:20:51默认[20171117t071753] ... 29个常用框架省略 2017-11-17 00:20:51默认[20171117t071753]引起:java.net.UnknownHostException:google at java.net.InetAddress.getAllByName0(InetAddress.java:1280)〜[na:1.8.0_131] java。 net.InetAddress.getAllByName(InetAddress.java:1192)〜[na:1.8.0_131] at java.net.InetAddress.getAllByName(InetAddress.java:1126)~ [na:1.8.0_131] at com.mysql.jdbc。 com.mysql.jdbc.MysqlIO上的StandardSocketFactory.connect(StandardSocketFactory.java:188)~ [mysql-connector-java-5.1.43.jar!/:5.1.43]。(MysqlIO.java:300)〜[mysql-连接器的Java-5.1.43.jar /:43年5月1日]

1 个答案:

答案 0 :(得分:0)

在我的应用程序属性中,我使用jdbc:mysql:// [host]:[port] / [dbname]?autoReconnect = true& useSSL = false表示url属性,它可以正常工作。

但在我看来,您的错误是由于您必须在您的cloud-sql实例的授权部分授权您的应用引擎的IP地址。

Configuring IP Access on Cloud SQL instance