2017年1月

package main

import (
    "database/sql"
    "fmt"
    _ "github.com/go-sql-driver/mysql"
)

func main() {
    db, err := sql.Open("mysql", "root:root@tcp(127.0.0.1:3306)/test?charset=utf8")

    if err != nil {
        panic(err.Error())
    }
    defer db.Close()

    rows, err := db.Query("select user_id,access_token from user_session")
    if err != nil {
        panic(err.Error())
    }

    var user_id int
    var access_token string

    for rows.Next() {
        err := rows.Scan(&user_id, &access_token)
        if err != nil {
            panic(err.Error())
        }
        fmt.Println(user_id, access_token)
    }

}