【问题标题】:Cannot connect to Second Generation Cloud SQL database无法连接第二代 Cloud SQL 数据库
【发布时间】:2016-10-05 05:12:00
【问题描述】:

目前我正在尝试关注此documentation 以连接到我的第二代云 SQL 数据库。但是,我的应用程序在启动时失败,因为它无法连接到它..

如文档所述,我已添加两个服务帐户

my-project@appspot.gserviceaccount.com
1234-compute@developer.gserviceaccount.com

作为IAM下的编辑

我正在使用 Cloud SQL 实例的 IPv4 进行连接。这里是连接字符串:

jdbc:mysql://w.x.y.z:3306/app_db?useSSL=false

但在Stackdriver Logging 视图中我看到了:

[main] ERROR com.mz.server.BootstrappingServerConfig - Error trying to migrate SQL scripts ..
org.flywaydb.core.api.FlywayException: Unable to obtain Jdbc connection from DataSource
    at org.flywaydb.core.internal.util.jdbc.JdbcUtils.openConnection(JdbcUtils.java:56)
    at org.flywaydb.core.Flyway.execute(Flyway.java:1385)
    at org.flywaydb.core.Flyway.migrate(Flyway.java:1006)
    ...
Caused by: 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.
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    ...
Caused by: java.net.ConnectException: Connection timed out
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
    ...

两个实例位于同一区域:us-central1-b 用于计算实例,us-central1 用于 SQL 实例。

我的 app.yaml 文件:

runtime: java
vm: true

runtime_config:
  jdk: openjdk8
  server: jetty9

env_variables:
  'ALPN_ENABLE': 'true'   # OPTIONAL

beta_settings:
  cloud_sql_instances: mz-test:us-central1:mz-test-cloudsql

health_check:
  enable_health_check: false

我不确定这里出了什么问题。我真的可以使用 SQL 实例的本地 IPv4 地址吗?

文档实际上说

"在您的应用程序代码中,通过打开具有以下名称的套接字连接到实例:/cloudsql/[INSTANCE_CONNECTION_NAME}"

但我不确定这对连接字符串意味着什么。

我还遗漏了有关需要什么用户名/密码的信息,还是这里不需要?

为什么我无法连接?

【问题讨论】:

标签: mysql google-app-engine google-compute-engine google-cloud-sql


【解决方案1】:

对于在 App Engine 柔性环境应用程序上运行的 Java 应用程序,请使用以下库:https://github.com/GoogleCloudPlatform/cloud-sql-mysql-socket-factory

【讨论】:

    猜你喜欢
    • 2017-10-20
    • 2018-08-04
    • 2016-04-28
    • 1970-01-01
    • 1970-01-01
    • 2019-11-10
    • 2018-12-19
    • 1970-01-01
    • 2011-11-25
    相关资源
    最近更新 更多