How to connect to Google Cloud SQL with go-sql-driver/mysql on App Engine?

不羁的心 提交于 2019-12-02 05:12:08

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!

The DSN (data source name) you're giving to sql.Open doesn't look like the one in the docs:

import "database/sql"
import _ "<some mysql package>"

db, err := sql.Open("mysql", "cloudsql:my-instance*dbname/user/passwd")

Source: Go AppEngine Cloud SQL Reference

Edit: It looks like you're using the correct DSN format for your SQL package as documented here. My guess at that point is that it's correctly connecting to the database, but that either the user isn't being accepted or, for whatever reason, doesn't have the correct permissions.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!