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", "rm-bp11t1616a1kjvmx5.mysql.rds.aliyuncs.com: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 }