[英]Cannot connect to Google Cloud SQL using SSL + Golang from Google App Engine
Google says you can connect to Google Cloud SQL using Golang and the go-sql-driver
like so: 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")
ref: https://cloud.google.com/appengine/docs/go/cloud-sql/reference 参考: https : //cloud.google.com/appengine/docs/go/cloud-sql/reference
... However, this (for me) generates a x509 certificate error: ...但是,这(对我来说)会生成x509证书错误:
x509: certificate is valid for projectName:instanceName, not projectName x509:证书对projectName有效:instanceName,而不是projectName
I cannot figure out how to solve this. 我无法弄清楚如何解决这个问题。 Adding the instance name again (even though it's already there) in the connection string does not help, nor is correct according to Google's own docs. 根据Google自己的文档,在连接字符串中再次添加实例名称(即使它已经存在)也无济于事。
Has anyone managed to make this work? 有没有人设法做到这一点? What is wrong? 怎么了?
Are you connecting with SSL? 你用SSL连接了吗? This error message indicates that must set the ServerName
property when you register your custom TLSConfig with the mysql driver, in addition to specifying the project-id:instance-name
inside sql.Open()
. 此错误消息表明, 除了在sql.Open()
指定project-id:instance-name
之外 , 还必须在使用mysql驱动程序注册自定义TLSConfig时设置ServerName
属性。
eg Use the TLS setup from the docs , but add a ServerName
in your call to RegisterTLSConfig
: 例如,使用文档中的TLS设置,但在对RegisterTLSConfig
的调用中添加ServerName
:
mysql.RegisterTLSConfig("custom", &tls.Config{
RootCAs: rootCertPool,
Certificates: clientCert,
ServerName: "projectName:instanceName",
})
Then append ?tls=nameOfYourCustomTLSConfig
然后追加?tls=nameOfYourCustomTLSConfig
db, err := sql.Open("mysql", "user@cloudsql(project-id:instance-name)/dbname?tls=custom")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.