Skip to content

Commit

Permalink
Update mysql.go
Browse files Browse the repository at this point in the history
优化conn.InitMysql:建立mysql连接的时候会加载Host以及Port配置
  • Loading branch information
Ccheers authored Feb 7, 2020
1 parent e8f3ca2 commit 3b76c14
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions conn/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func InitMysql(options ...Sp) (*xorm.Engine,error){
option(q)
}

dataSourceName := q.UserName + ":" + q.Password + "@/" + q.DataBase + "?charset=utf8"
dataSourceName := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8", q.UserName, q.Password, q.Host, q.Port, q.DataBase)
engine, err := xorm.NewEngine("mysql", dataSourceName)
if err != nil {
zgh.ZLog().Error("mysql","初始化数据库,创建连接异常:"+err.Error())
Expand Down Expand Up @@ -140,4 +140,4 @@ func SqlDump(fileName string,filePath string) error {
return err
}
return nil
}
}

0 comments on commit 3b76c14

Please sign in to comment.