如何使用App Engine上的go-sql-driver / mysql连接到Google Cloud SQL? [英] How to connect to Google Cloud SQL with go-sql-driver/mysql on App Engine?

查看:157
本文介绍了如何使用App Engine上的go-sql-driver / mysql连接到Google Cloud SQL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Go上使用 go-sql-driver / mysql 驱动程序App Engine连接到这样的Cloud SQL实例:

  import(
database / sql
_github.com/go-sql-driver/mysql

$ b $ db,dbErr:= sql.Open(mysql,root @ cloudsql(project:instance) / database
...
pingErr:= db.Ping()

但我在 pingErr 中获得了拒绝权限



当然,我已经在访问控制下的云SQL控制台中检查了我的应用程序的授权每个文档我也尝试添加一个具有权限的MySQL用户,并使用 user:password 来代替 root

我在做什么错?



...

p>

更新:

$ b @ b

Per @ Kyle的建议我尝试了另一种驱动程序和它与以下代码一起工作:

  import(
database / sql
_github。 com / ziutek / mymysql / godrv
_github.com/ziutek/mymysql/mysql
_github.com/ziutek/mymysql/native


db,dbErr:= sql.Open(mymysql,cloudsql:project:instance * database / user / password

猜猜是时候在 go-sql-driver / mysql上执行pull request 如果我能弄清楚发生了什么问题!任何见解或经验都会受到赞赏!

解决方案

这是版本问题

如果仔细观察,App Engine支持添加到主分支,但最新版本为1.1 ,并且不包括它。



而不是去获取github.com/go-sql-driver/mysql 你需要手动 git clone https://github.com/go-sql-driver/mysql (master branch)into $ GOPATH / src / 然后部署到App Engine!



来自作者的这个评论是让我失望的,@凯尔的建议是尝试另一个驱动程序(它的工作)促使我重新读取所有内容股份公司ain - 谢谢!

I'm using the go-sql-driver/mysql driver in Go on App Engine to connect to a Cloud SQL instance like this:

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

db, dbErr := sql.Open("mysql", "root@cloudsql(project:instance)/database"
...
pingErr := db.Ping()

but I get "permission denied" in pingErr.

Of course, I've checked my app is authorized in the Cloud SQL console under "Access Control" per the docs. I also tried adding a MySQL user with privileges and using user:password in place of root and even not specifying a user.

What am I doing wrong?

...

Update:

Per @Kyle's suggestion I tried an alternate driver ziutek/mymysql and it works with the following code:

import (
   "database/sql"
   _ "github.com/ziutek/mymysql/godrv"
   _ "github.com/ziutek/mymysql/mysql"
   _ "github.com/ziutek/mymysql/native"
)

db, dbErr := sql.Open("mymysql", "cloudsql:project:instance*database/user/password"

Guess it's time for a pull request on go-sql-driver/mysql if I can figure out what's going wrong! Any insights or experience appreciated!

解决方案

It's a versioning issue!

If you look carefully, App Engine support was added to the master branch but the latest release is 1.1 and doesn't include it.

Instead of go get github.com/go-sql-driver/mysql you need to manually git clone https://github.com/go-sql-driver/mysql (master branch) into $GOPATH/src/ and then deploy to App Engine!

This comment from the author is what tipped me off and @Kyle's suggestion to try another driver (which worked) motivated me to re-read everything again - thanks!

这篇关于如何使用App Engine上的go-sql-driver / mysql连接到Google Cloud SQL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆