This is a creation in Article, where the information may have evolved or changed.
Using go-sql-driver to manipulate MYQL databases
Package Mainimport ("Database/sql" _ "Github.com/go-sql-driver/mysql" "FMT") func main () {//Connect database, get connection handle db, err: = SQL. Open ("MySQL", "root:123456@tcp (localhost:3306)/huifang5?charset=utf8") if err! = Nil {panic (err. Error ())}defer db. Close ()//executes the SQL statement to return multiple rows of result set results, err: = db. Query ("select * from Hf_test where keshiid=?", 0) if err! = Nil {panic (err). Error ())}defer result. Close ()//scan required Container keys, _: = result. Columns () //Field name values: = Make ([][]byte, Len (keys)) //Field value scans: = Make ([]interface{}, Len (keys))//scan container for I: = Range scans {Scans[i] = &values[i]//handling of the container so that each field value can be collected after the scan}//loop out the data for each row var datas []map[string]stringfor Result. Next () {result. Scan (Scans ...) Data: = Make (map[string]string) for k, V: = Range values {key: = Keys[k]data[key] = string (v)}datas = append (datas, data)}f Mt. Println (Datas)}