drone-test/client/mysql.go
2022-06-15 10:31:40 +08:00

24 lines
570 B
Go

package client
import (
"gitee.ltd/lxh/logger"
"gitee.ltd/lxh/logger/log"
"gorm.io/driver/mysql"
"gorm.io/gorm"
)
var MySQL *gorm.DB
// InitMySQLClient 初始化MySQL客户端
func InitMySQLClient() {
// 创建连接对象
conn, err := gorm.Open(mysql.Open("root:Tw2022!@#@tcp(47.109.17.77:3306)/tuowei?charset=utf8mb4&parseTime=True&loc=Local&timeout=1000ms"), &gorm.Config{Logger: logger.DefaultGormLogger()})
if err != nil {
log.Panicf("初始化MySQL连接失败, 错误信息: %v", err)
} else {
log.Debug("[MySQL] 连接成功")
}
MySQL = conn
}