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.
|
||||
case "mysql":
|
||||
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 {
|
||||
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{})
|
||||
// Connect to a SQLite database.
|
||||
|
|
Loading…
Reference in New Issue