package main
import (
"database/sql"
"fmt"
_ "github.com/go-sql-driver/mysql"
)
func connectDB() (db *sql.DB, err error) {
dbDriver := "mysql"
dbUser := "root"
dbPass := "123456"
dbName := "nilpointer"
db, err = sql.Open(dbDriver, dbUser+":"+dbPass+"@/"+dbName)
return
}
func main() {
_, err := connectDB()
if err != nil {
fmt.Println(err)
} else {
fmt.Println("Success")
}
}
Output
Success