diff --git a/src/common/dao/mysql.go b/src/common/dao/mysql.go index 8313add26..1999b0208 100644 --- a/src/common/dao/mysql.go +++ b/src/common/dao/mysql.go @@ -16,6 +16,7 @@ package dao import ( "fmt" + "time" "github.com/astaxie/beego/orm" _ "github.com/go-sql-driver/mysql" //register mysql driver @@ -58,7 +59,12 @@ func (m *mysql) Register(alias ...string) error { } conn := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s", m.usr, m.pwd, m.host, m.port, m.database) - return orm.RegisterDataBase(an, "mysql", conn) + if err := orm.RegisterDataBase(an, "mysql", conn); err != nil { + return err + } + db, _ := orm.GetDB(an) + db.SetConnMaxLifetime(5 * time.Minute) + return nil } // Name returns the name of MySQL