简体   繁体   English

无法使用Google App Engine中的SSL + Golang连接到Google Cloud SQL

[英]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.

相关问题 NodeJ:无法从Google App Engine连接Google Cloud SQL - NodeJs:Unable to connect Google Cloud SQL from Google App Engine Google App Engine 上的 Django 连接到云 SQL,无法连接 - Django on Google App Engine connection to Cloud SQL, cannot connect 使用mysqli_connect连接到Google App Engine中的Cloud SQL - Connect to Cloud SQL in Google App Engine using mysqli_connect Google App Engine-使用mysqli用php连接到SQL Cloud实例 - Google App Engine - Connect to SQL Cloud Instance with php using mysqli 使用Google App Engine端点连接到Cloud SQL - Connect to Cloud SQL with Google App Engine Endpoint 无法从我的App Engine访问Google Cloud SQL数据库 - Cannot access Google Cloud SQL database from my App Engine 如何使用App Engine从Eclipse连接到Google Cloud SQL实例? - How to connect to google cloud sql instance from eclipse using App Engine? 无法使用ZF2中的Pdo_Mysql通过Google App Engine连接到Google Cloud SQL - Cannot connect to Google Cloud SQL through Google App Engine with Pdo_Mysql in ZF2 无法使用Google App Engine上的Slim框架连接到Google Cloud SQL - Not able to connect to Google Cloud SQL with Slim framework on Google App Engine 无法使用SSL和Google Compute上的PDO连接到Google Cloud MySQL - Cannot connect to Google Cloud MySQL using SSL with PDO on Google Compute
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM