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", "172.31.37.71:3306", "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 }