我发现go / MysqL文档混乱.似乎没有一个例子如何连接到远程主机.像大家一样会使用localhost.
到目前为止我有这个
import ( "database/sql" _ "github.com/ziutek/myMysqL/godrv" db,err := sql.Open("myMysqL","tcp:"+dbHost*dbName+"/"+user+"/"+pass) defer db.Close()
根据https://github.com/ziutek/mymysql的文档
[PROTOCOL_SPECFIIC*]DBNAME/USER/PASSWD // // where protocol specific part may be empty (this means connection to // local server using default protocol). Currently possible forms: // DBNAME/USER/PASSWD // unix:SOCKPATH*DBNAME/USER/PASSWD // unix:SOCKPATH,OPTIONS*DBNAME/USER/PASSWD // tcp:ADDR*DBNAME/USER/PASSWD // tcp:ADDR,OPTIONS*DBNAME/USER/PASSWD
我也试过
db,"tcp:"+dbHost,dbName+"/"+user+"/"+pass)
它也不工作.整个句法看起来很神秘.