dtp/mysql/client.go

28 lines
479 B
Go
Raw Normal View History

2024-07-28 19:10:26 +08:00
package mysql
import (
"fmt"
_ "github.com/go-sql-driver/mysql"
"github.com/jmoiron/sqlx"
)
func NewMysqlDB() (*sqlx.DB, error) {
dsn := fmt.Sprintf(
"%s:%s@(%s)/%s?charset=utf8&parseTime=true&timeout=%ds&readTimeout=%ds&writeTimeout=%ds",
"root",
"Wishpal2024",
2024-08-20 18:08:35 +08:00
"172.31.37.71:3306",
2024-07-28 19:10:26 +08:00
"vas",
3,
5,
3,
)
db, err := sqlx.Open("mysql", dsn)
if err != nil {
fmt.Printf("NewMysqlDB fail, dsn: %v,err: %v\n", dsn, err)
return nil, err
}
return db, err
}