4
我正在使用go-sql-driver嘗試Google Cloud SQL。我卡在這裏我不知道這裏有什麼錯。這個錯誤對我來說完全是未知的。來自Google CloudSQL的錯誤HTTP響應
package hello
import (
"fmt"
"net/http"
"database/sql"
_ "github.com/go-sql-driver/mysql"
)
func init() {
http.HandleFunc("/", handler)
}
func handler(w http.ResponseWriter, r *http.Request) {
const dbUserName = "userName"
const dbPassword = "password"
const dbIP = "123.123.231.123"
db, err := sql.Open("mysql", dbUserName+":"+dbPassword+"@"+dbIP+":3306/user")
if err != nil {
panic(err.Error())
}
// Query the name
rows, err := db.Query("SELECT * FROM user")
if err != nil {
panic(err.Error())
}
fmt.Println(rows)
defer db.Close()
}
錯誤:
the runtime process gave a bad HTTP response: ''
2015/04/12 09:23:36 http: panic serving 127.0.0.1:50091: Default addr for network '173.194.106.126:3306' unknown
goroutine 6 [running]:
net/http.func·011()
/private/var/folders/00/0v42r000h01000cxqpysvccm003chb/T/appengine/go_appengine/goroot/src/net/http/server.go:1130 +0xbb
main37089.handler(0x5ad1e0, 0xc208044280, 0xc2080331e0)
任何想法。看看go-sql-driver源碼的來源,也許我應該設置一個默認地址?
如果在DSN中添加tcp協議會發生什麼?例如用戶:pass @ tcp(123.123.123.123:3306)/ dbname?如果不指定dbname,會發生什麼情況? – cflewis
你不需要'cloudsql:instance-name * ...'來暴露數據庫的訪問嗎?閱讀[this](https://cloud.google.com/appengine/docs/go/cloud-sql/reference),它可能很有用。 – Anzel
@Anzel我也試過。它不會在開發,即我的本地。當我將它上傳到應用程序引擎時,它可以工作 – avellable