标签:
aaaa
package main import ( "database/sql" "fmt" _ "github.com/Go-SQL-Driver/MySQL" //引入mysql驱动 ) func main() { db, err := sql.Open("mysql", "root:123456@tcp(localhost:3306)/test?charset=utf8") CheckErr(err) rows, err := db.Query("select * from users") CheckErr(err) for rows.Next() { var id int var username string var password string err = rows.Scan(&id, &username, &password) CheckErr(err) fmt.Println(username) fmt.Println(password) } db.Close() } func CheckErr(err error) { if err != nil { panic(err) } }
标签:
原文地址:http://www.cnblogs.com/project/p/5171422.html