I know this is a AppEngine topic, but this forum is the best Go forum.
Does anyone have an example of how to connect a Go AppEngine app to google cloud sql?
The below package gets me connecting to the server, but I am denied because I am forced to supply a user/pass when I dont need to because my appengine app is authenticated to use the database.
Received #1045 error from MySQL server: "Access denied for user 'root'@'localhost' (using password: YES)"
Someone must have an example lying around where they have done this, I searched for hours and there is nothing that works.
"database/sql"
_ "
github.com/ziutek/mymysql/godrv"
_ "
github.com/ziutek/mymysql/mysql"
_ "
github.com/ziutek/mymysql/native"
func areaHandler(res http.ResponseWriter, r *http.Request, p httprouter.Params) {
areaName := SHA1(p.ByName("areaName"))
userName := SHA1("testuser")
ds := DS(r)
db, err := sql.Open("mymysql", "cloudsql:my-project:app-sql*testdb/root/1234")
if err != nil { ds.Error("areaHandler", err); fmt.Fprintf(res, err.Error()); return }
defer db.Close()
_, err = db.Query("CREATE TABLE IF NOT EXISTS follow_area (uid int PRIMARY KEY AUTO_INCREMENT, area VARCHAR(40), user VARCHAR(16));")
if err != nil { ds.Error("areaHandler", err); fmt.Fprintf(res, err.Error()); return }
_, err = db.Query("SELECT * FROM follow_area WHERE user='"+userName+"' AND area='"+areaName+"';")
if err != nil { ds.Error("areaHandler", err); fmt.Fprintf(res, err.Error()) }
}