将 App Engine 连接到 Google 云 SQL 失败
Connect App Engine to Google cloud SQL fails
我正在关注这个 guide
我正在这样填写配置:
val datasourceConfig = HikariConfig().apply {
jdbcUrl = "jdbc:mysql:///$DB_NAME"
username = DB_PASS
password = DB_USER
mapOf(
"cloudSqlInstance" to CLOUD_SQL_CONNECTION_NAME,
"socketFactory" to "com.google.cloud.sql.mysql.SocketFactory",
"ipTypes" to "PUBLIC,PRIVATE",
).forEach {
addDataSourceProperty(
it.key,
it.value
)
}
}
gcloud sql instances describe project-name
的输出:
backendType: SECOND_GEN
connectionName: project-name:europe-west1:project-name-db
databaseVersion: MYSQL_5_7
failoverReplica:
available: true
gceZone: europe-west1-d
instanceType: CLOUD_SQL_INSTANCE
ipAddresses:
- ipAddress: *.*.*.*
type: PRIMARY
kind: sql#instance
name: project-name-db
project: project-name
region: europe-west1
我正在从中填充我的环境变量:
DB_NAME=project-name-db
CLOUD_SQL_CONNECTION_NAME=project-name:europe-west1:project-name-db
在已部署的应用程序行上 val dataSource = HikariDataSource(datasourceConfig)
崩溃,出现以下异常:
com.zaxxer.hikari.pool.HikariPool$PoolInitializationException: Failed to initialize pool: Cannot connect to MySQL server on localhost:3,306.
Make sure that there is a MySQL server running on the machine/port you are trying to connect to and that the machine this software is running on is able to connect to this host/port (i.e. not firewalled). Also make sure that the server has not been started with the --skip-networking flag.
更新:根据 ,我尝试在第二个和第三个斜杠 ("jdbc:mysql://google/$DB_NAME"
) 之间添加 google
,现在我得到:
Cannot connect to MySQL server on google:3,306.
我缺少以下依赖项:
implementation("com.google.cloud.sql:mysql-socket-factory-connector-j-8:1.2.2")
更多信息here
此外,DB_NAME
不是 gcloud sql instances
输出的名称,而是应该在控制台 -> 项目 -> Sql -> 数据库
中创建的数据库名称
我正在关注这个 guide
我正在这样填写配置:
val datasourceConfig = HikariConfig().apply {
jdbcUrl = "jdbc:mysql:///$DB_NAME"
username = DB_PASS
password = DB_USER
mapOf(
"cloudSqlInstance" to CLOUD_SQL_CONNECTION_NAME,
"socketFactory" to "com.google.cloud.sql.mysql.SocketFactory",
"ipTypes" to "PUBLIC,PRIVATE",
).forEach {
addDataSourceProperty(
it.key,
it.value
)
}
}
gcloud sql instances describe project-name
的输出:
backendType: SECOND_GEN
connectionName: project-name:europe-west1:project-name-db
databaseVersion: MYSQL_5_7
failoverReplica:
available: true
gceZone: europe-west1-d
instanceType: CLOUD_SQL_INSTANCE
ipAddresses:
- ipAddress: *.*.*.*
type: PRIMARY
kind: sql#instance
name: project-name-db
project: project-name
region: europe-west1
我正在从中填充我的环境变量:
DB_NAME=project-name-db
CLOUD_SQL_CONNECTION_NAME=project-name:europe-west1:project-name-db
在已部署的应用程序行上 val dataSource = HikariDataSource(datasourceConfig)
崩溃,出现以下异常:
com.zaxxer.hikari.pool.HikariPool$PoolInitializationException: Failed to initialize pool: Cannot connect to MySQL server on localhost:3,306.
Make sure that there is a MySQL server running on the machine/port you are trying to connect to and that the machine this software is running on is able to connect to this host/port (i.e. not firewalled). Also make sure that the server has not been started with the --skip-networking flag.
更新:根据 "jdbc:mysql://google/$DB_NAME"
) 之间添加 google
,现在我得到:
Cannot connect to MySQL server on google:3,306.
我缺少以下依赖项:
implementation("com.google.cloud.sql:mysql-socket-factory-connector-j-8:1.2.2")
更多信息here
此外,DB_NAME
不是 gcloud sql instances
输出的名称,而是应该在控制台 -> 项目 -> Sql -> 数据库