Skip to content

Commit

Permalink
dont escape for mysql password
Browse files Browse the repository at this point in the history
  • Loading branch information
zhijian-pro committed Sep 26, 2023
1 parent 1100206 commit dce7896
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions pkg/meta/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,22 @@ func newSQLMeta(driver, addr string, conf *Config) (Meta, error) {
}
}
}

// escaping is not necessary for mysql password https://github.com/go-sql-driver/mysql#password
if driver == "mysql" {
colonIndex := strings.Index(addr, ":")
atIndex := strings.LastIndex(addr, "@")
pwd := addr[colonIndex+1 : atIndex]
parse, err := url.Parse("mysql://root:" + pwd + "@127.0.0.1")
if err != nil {
return nil, fmt.Errorf("parse url %s failed: %s", addr, err)
}
originPwd, ok := parse.User.Password()
if ok {
addr = fmt.Sprintf("%s:%s%s", addr[:colonIndex], originPwd, addr[atIndex:])
}
}

engine, err := xorm.NewEngine(driver, addr)
if err != nil {
return nil, fmt.Errorf("unable to use data source %s: %s", driver, err)
Expand Down

0 comments on commit dce7896

Please sign in to comment.