package main import ( "fmt" "database/sql" _"./gomysql" // ) func main(){ db, err := sql.Open("mysql","root:123123123@tcp(localhost:3306)/GL?charset=utf8"); if err != nil { fmt.Printf("%s\n",err); return ; } rows, err := db.Query("select * from img_inf"); if err != nil { fmt.Printf("%s\n",err); return ; } if rows == nil { fmt.Printf("rows is nil!\n"); return ; } for rows.Next() { var u,s string; err = rows.Scan(&u,&s); if err != nil { fmt.Printf("%s\n",err); break; } fmt.Printf("%s %s\n",u,s); } return ; }
go-mysql-driver 下载地址:http://download.csdn.net/detail/juxuny/5315592
有疑问加站长微信联系(非本文作者)