我在这里看到了其他同一问题的帖子,但是没有一个答案对我有帮助。我有一个谷歌SQLCloud第二代数据库,我试图让我的Go Appengine应用程序建立连接。 我使用go-sql-driver/mysql使用Go on AppEngine连接到Google SQL Cloud第二代
起初,我试图用我的第一代只是路过的项目和实例名作为参数,使用相同的方式连接:
sql.Open("mysql", "[email protected](project:instance)/database"
然后我从云发现控制台也从this post该地区也需要让我的连接参数现在看起来像:
sql.Open("mysql", "[email protected](project:uscentral1:instance)/database"
,并与密码
sql.Open("mysql", "root:[email protected](project:uscentral1:instance)/database"
仍然没有工作
我最后的尝试是使用SSL连接的使用从驱动程序文件提供的代码上this post描述:
rootCertPool := x509.NewCertPool()
pem, err := ioutil.ReadFile("/path/ca-cert.pem")
if err != nil {
log.Fatal(err)
}
if ok := rootCertPool.AppendCertsFromPEM(pem); !ok {
log.Fatal("Failed to append PEM.")
}
clientCert := make([]tls.Certificate, 0, 1)
certs, err := tls.LoadX509KeyPair("/path/client-cert.pem", "/path/client-key.pem")
if err != nil {
log.Fatal(err)
}
clientCert = append(clientCert, certs)
mysql.RegisterTLSConfig("custom", &tls.Config{
RootCAs: rootCertPool,
Certificates: clientCert,
})
sql.Open("mysql","root:[email protected](project:uscentral1:instance)/database?tls=custom")
也没有运气。
在这一点上,我只是想尽办法解决问题。有没有人做过与大多数人所做的不同之处?此时,我不确定问题是否出现在我的代码中,驱动程序或CloudSQL数据库中的某些配置。
谢谢@Vadim。请看我上面的答案。 –