dshgdhdfcas30210 2014-10-02 11:20
浏览 32

Golang GAE与Google Cloud SQL的集成

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"
})
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 使用yolov5-7.0目标检测报错
    • ¥15 对于这个问题的解释说明
    • ¥200 询问:python实现大地主题正反算的程序设计,有偿
    • ¥15 smptlib使用465端口发送邮件失败
    • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
    • ¥15 对于squad数据集的基于bert模型的微调
    • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
    • ¥20 steam下载游戏占用内存
    • ¥15 CST保存项目时失败
    • ¥20 java在应用程序里获取不到扬声器设备