fix(db): need to set charset, parseTime and loc in connection for mysql
This commit is contained in:
parent
993b9e8208
commit
5d15ca330a
4
db/db.go
4
db/db.go
|
@ -35,9 +35,9 @@ func Init() {
|
||||||
// Connect to a MySQL database.
|
// Connect to a MySQL database.
|
||||||
case "mysql":
|
case "mysql":
|
||||||
if dbSocket != "" {
|
if dbSocket != "" {
|
||||||
dsn = fmt.Sprintf("%s:%s@unix(%s)/%s", dbUser, dbPassword, dbSocket, dbName)
|
dsn = fmt.Sprintf("%s:%s@unix(%s)/%s?charset=utf8mb4&parseTime=True&loc=Local", dbUser, dbPassword, dbSocket, dbName)
|
||||||
} else {
|
} else {
|
||||||
dsn = fmt.Sprintf("%s:%s@tcp(%s:%d)/%s", dbUser, dbPassword, dbHost, dbPort, dbName)
|
dsn = fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8mb4&parseTime=True&loc=Local", dbUser, dbPassword, dbHost, dbPort, dbName)
|
||||||
}
|
}
|
||||||
db, err = gorm.Open(mysql.Open(dsn), &gorm.Config{})
|
db, err = gorm.Open(mysql.Open(dsn), &gorm.Config{})
|
||||||
// Connect to a SQLite database.
|
// Connect to a SQLite database.
|
||||||
|
|
Loading…
Reference in New Issue