I'm having a lot of trouble connecting my Golang GAR to Google Cloud SQL. I'm currently using https://github.com/go-sql-driver/mysql driver. My connection string is
db, err := sql.Open("mysql", "'root:password'@tcp(ip-address:3306)/dbname")
I always get 1045 error, according to Google:
If MySQL rejects the connection, for example, because you have specified an incorrect MySQL user name or password, the error you receive will be: ERROR 1045 (28000): Access denied for user 'user-name'@'client-IP' (using password: YES)
When I connect to the db via SQL command line tool with the same username and password, I get access.
I doubled checked myself and went over all the SQL db creation steps including providing my IP address as authorized to connect the SQL db and creating user via MySQL command line.
There might be some problem with the string of the user name and pass that I'm providing to the Go SQL driver: "'root:password'@tcp(ip-address:3306)/dbname".
import (
"time"
"net/http"
"database/sql"
_ "github.com/mysql"
"appengine"
"appengine/datastore"
/*"appengine/user"*/
"github.com/go-martini/martini"
"github.com/codegangsta/martini-contrib/binding"
)
m.Get("/GetTheShop/:Bid" , func(params martini.Params,w http.ResponseWriter, r *http.Request) string{
db, err := sql.Open("mysql", "cloudsql:insName*db/user/pass")
if err != nil {
return(err.Error()+" 1")
}
defer db.Close()
// Open doesn't open a connection. Validate DSN data:
err = db.Ping()
if err != nil {
return(err.Error()+" 2")
}
return "db connected"
})