问题描述
我在Go上使用驱动程序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的建议我尝试了另一种驱动程序如果我能弄清楚发生了什么问题!任何见解或经验都会受到赞赏!
解决方案 这是版本问题!
如果仔细观察,App Engine支持,但,并且不包括它。
而不是去获取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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!