Skip to content

Commit

Permalink
update mysql connect params
Browse files Browse the repository at this point in the history
  • Loading branch information
cyub committed May 10, 2021
1 parent 0dbe2d8 commit 444157b
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions mysql/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,23 @@ var db *gorm.DB
// Provider use for mount to app bootstrap
func Provider() app.ComponentMount {
return func(app *app.App) (err error) {
dsn := fmt.Sprintf("%s:%s@(%s:%d)/%s?charset=utf8&parseTime=True&loc=Local",

dsn := fmt.Sprintf("%s:%s@(%s:%d)/%s?&loc=%s&parseTime=%s&collation=%s",
app.Config.GetString("mysql.user", "homestead"),
app.Config.GetString("mysql.passwd", "secret"),
app.Config.GetString("mysql.host", "localhost"),
app.Config.GetInt("mysql.port", 3306),
app.Config.GetString("mysql.db", "homestead"),
app.Config.GetString("mysql.db", "hyper"),
app.Config.GetString("mysql.loc", "UTC"),
app.Config.GetString("mysql.parse_time", "true"),
app.Config.GetString("mysql.collation", "utf8mb4_general_ci"),
)
// all parameters see https://github.com/go-sql-driver/mysql#parameters
// https://github.com/go-sql-driver/mysql#charset
charset := app.Config.GetString("mysql.charset", "")
if len(charset) > 0 {
dsn += "&charset=" + charset
}

db, err = gorm.Open("mysql", dsn)
if err != nil {
Expand Down

0 comments on commit 444157b

Please sign in to comment.