My Test code likes:
package main
import (
"fmt"
"math/rand"
"time"
"log"
"database/sql"
_ "github.com/go-sql-driver/mysql"
)
func main() {
db, err := sql.Open("mysql", "username:password@tcp(55b5f18rtr8895.sh.cdb.myqcloud.com:7863)/bsk")
if err != nil {
log.Println(err)
}
db.SetConnMaxLifetime(100 * 100)
db.SetMaxIdleConns(10)
db.SetMaxOpenConns(50)
defer db.Close()
db.Ping()
err = db.Ping()
if err != nil {
log.Println(err)
}
}
And the error is:
driver: bad connection
I am sure the mysql host and port is roght. But i just can't find any problems here, please help me.
I used db.Ping()
twice, if one was removed than it works.