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!