如何使用App Engine上的go-sql-driver / mysql连接到Google Cloud SQL? [英] How to connect to Google Cloud SQL with go-sql-driver/mysql on App Engine?
问题描述
我在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 $ c $甚至没有指定用户。
我在做什么错?
...
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: but I get "permission denied" in 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 What am I doing wrong? ... Update: Per @Kyle's suggestion I tried an alternate driver ziutek/mymysql and it works with the following code: 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 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屋!import (
"database/sql"
_ "github.com/go-sql-driver/mysql"
)
db, dbErr := sql.Open("mysql", "root@cloudsql(project:instance)/database"
...
pingErr := db.Ping()
pingErr
.user:password
in place of root
and even not specifying a user.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 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!