是go的mysql clinet library.
網站位於 http://github.com/eden/mysqlgo
安裝非常簡單 ( ubuntu 需要裝 libmysqlclient-dev 裡面會用到 mysql_config )
$ git clone git://github.com/eden/mysqlgo.git
$ cd mysqlgo
$ make install
$ make example
$ ./example -host=127.0.0.1 -user=root -dbname=test
使用容易
- 代碼: 選擇全部
package main
import ( "mysql"; "fmt"; "rand"; )
func main(){
conn, _ := mysql.Open(fmt.Sprintf("mysql://go:gogogo@127.0.0.1:3306/godb"));
stmt, _ := conn.Prepare("CREATE TABLE hello (i INT, s VARCHAR(255))");
conn.Execute(stmt);
stmt, _ = conn.Prepare("INSERT INTO hello (i, s) VALUE (?, ?)");
for i := 0; i < 100; i += 1 {
conn.Execute(stmt, rand.Int(), fmt.Sprintf("id%d", rand.Int()));
}
stmt, _ = conn.Prepare("SELECT * from hello");
rs, _ := conn.Execute(stmt);
for res := range rs.Iter() {
row := res.Data();
fmt.Printf("%d %s\n", row[0], row[1])
}
stmt.Close(); conn.Close();
}

