How to connect to Google Cloud SQL using go-sql-driver / mysql in App Engine?

I am using the go-sql-driver / mysql driver in the Google App Engine to connect to a Cloud SQL instance as follows:

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 " resolved rejection " in pingErr.

Of course, I checked that my application is allowed in the Cloud SQL console in the "Access Control" section for documents . I also tried to add the MySQL user with privileges and use user:passwordinstead rootand not even specify the user.

What am I doing wrong?

...

Update:

Per @Kyle sentence I tried the alternative ziutek / mymysql driver and 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"

go-sql-driver/mysql, , ! !

+1
2

!

, App Engine ​​ , - 1.1 .

go get github.com/go-sql-driver/mysql git clone https://github.com/go-sql-driver/mysql ( ) $GOPATH/src/, App Engine!

- , , @Kyle ( ) - !

+4

DSN ( ), sql.Open, :

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

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

: SQL AppEngine

: , DSN SQL, . , , , - .

+2

All Articles