package main
import (
"database/sql"
"fmt"
_ "github.com/go-sql-driver/mysql"
"time"
)
func main() {
db, err := sql.Open("mysql", "root:xxxx@tcp(localhost:3306)/xxxx?charset=utf8")
checkErr(err)
defer db.Close()
err = db.Ping()
checkErr(err)
for {
_, err = db.Query("SELECT 1")
checkErr(err)
time.Sleep(1000 * time.Millisecond)
}
fmt.Println("over")
}
func checkErr(err error) {
if err != nil {
panic(err)
}
}
有疑问加站长微信联系(非本文作者)