我的Google App Engine应用无法通过以下方式连接到我的Google Cloud SQL实例
java.lang.RuntimeException: The Google Cloud SQL API is not enabled for project [{project-id}]. Please use the Google Developers Console to enable it: https://console.cloud.google.com/apis/api/sqladmin/overview?project={project-id}
at com.google.cloud.sql.core.SslSocketFactory.obtainInstanceMetadata(SslSocketFactory.java:389) ~[jdbc-socket-factory-core-1.0.4.jar!/:na]
at com.google.cloud.sql.core.SslSocketFactory.fetchInstanceSslInfo(SslSocketFactory.java:284) ~[jdbc-socket-factory-core-1.0.4.jar!/:na]
at com.google.cloud.sql.core.SslSocketFactory.getInstanceSslInfo(SslSocketFactory.java:264) ~[jdbc-socket-factory-core-1.0.4.jar!/:na]
at com.google.cloud.sql.core.SslSocketFactory.createAndConfigureSocket(SslSocketFactory.java:183) ~[jdbc-socket-factory-core-1.0.4.jar!/:na]
at com.google.cloud.sql.core.SslSocketFactory.create(SslSocketFactory.java:152) ~[jdbc-socket-factory-core-1.0.4.jar!/:na]
at com.google.cloud.sql.mysql.SocketFactory.connect(SocketFactory.java:48) ~[mysql-socket-factory-1.0.4.jar!/:na]
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:300) ~[mysql-connector-java-5.1.44.jar!/:5.1.44]
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2189) ~[mysql-connector-java-5.1.44.jar!/:5.1.44]
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2222) ~[mysql-connector-java-5.1.44.jar!/:5.1.44]
这很奇怪,因为我认为API已启用。 API仪表板有一个没有活动的Google Cloud SQL条目和一个“禁用”按钮。
该应用使用Cloud SQL Socket Factory:
jdbc:mysql://google/{database}?socketFactory=com.google.cloud.sql.mysql.SocketFactory&cloudSqlInstance={instance connection name copied from console}&useSSL=false
当应用程序在本地运行时,它会连接并更新远程Cloud SQL实例。
Cloud SQL实例是第2代HA,需要SSL。我试过的所有“gcloud sql”命令都成功了。我可以使用命令行工具和本地Cloud SQL代理与数据库进行交互。
在我点击API上的“启用”按钮之前,我想了解为什么API已经出现在API仪表板中(带有禁用选项),以及为什么只有来自Google App Engine的Cloud SQL Socket Factory连接实例失败。