【问题标题】:Cannot connect to Google Cloud SQL using SSL + Golang from Google App Engine无法使用来自 Google App Engine 的 SSL + Golang 连接到 Google Cloud SQL
【发布时间】:2016-09-12 13:52:22
【问题描述】:

Google 表示您可以使用 Golang 和 go-sql-driver 连接到 Google Cloud SQL,如下所示:

import "database/sql"
import _ "github.com/go-sql-driver/mysql"

db, err := sql.Open("mysql", "user@cloudsql(project-id:instance-name)/dbname")

参考:https://cloud.google.com/appengine/docs/go/cloud-sql/reference

...但是,这(对我而言)会生成 x509 证书错误:

x509:证书对 projectName:instanceName 有效,而不是 项目名称

我不知道如何解决这个问题。在连接字符串中再次添加实例名称(即使它已经存在)没有帮助,根据 Google 自己的文档也不正确。

有人设法完成这项工作吗?怎么了?

【问题讨论】:

  • 我希望您能分享有关您的设置的更多信息。你在 App Engine 上运行吗?您正在运行第一代/第二代吗?
  • 感谢您的回复...解决了以下问题。 :)
  • 顺便说一句,这是针对第一代的,但我在尝试使其在第二代上运行时遇到了这个错误:TLS requested but server does not support TLS

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


【解决方案1】:

您是否使用 SSL 连接?此错误消息表明,当您向 mysql 驱动程序注册自定义 TLSConfig 时,必须设置ServerName 属性,除了sql.Open() 中指定project-id:instance-name

例如使用 TLS 设置 from the docs,但在对 RegisterTLSConfig 的调用中添加 ServerName

mysql.RegisterTLSConfig("custom", &tls.Config{
            RootCAs:      rootCertPool,
            Certificates: clientCert,
            ServerName:   "projectName:instanceName",
        })

然后追加?tls=nameOfYourCustomTLSConfig

db, err := sql.Open("mysql", "user@cloudsql(project-id:instance-name)/dbname?tls=custom")

【讨论】:

  • 啊,明白了。我在任何地方都找不到这些信息。数据库连接终于成功了!我会将此信息转发给 Google 支持人员。
  • @BenGuild 很高兴听到!那么您在sql.Open() 调用中和周围是否有自定义 SSL 代码?
  • 是的,因此提示有关证书。 ;)
猜你喜欢
  • 2015-12-18
  • 1970-01-01
  • 2019-11-27
  • 2019-02-25
  • 2016-03-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-06-07
相关资源
最近更新 更多