1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-01-19 16:29:17 +08:00

fix: 解决 MySQL 8.x 切换数据库访问权限导致创建数据库失败的问题 (#2283)

This commit is contained in:
ssongliu 2023-09-14 10:58:14 +08:00 committed by GitHub
parent 5c0fb405d0
commit bf32424458
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 4 deletions

View File

@ -72,12 +72,14 @@ func (r *Local) CreateUser(info CreateInfo, withDeleteDB bool) error {
Timeout: 300}) Timeout: 300})
return err return err
} }
grantStr := fmt.Sprintf("grant all privileges on `%s`.* to %s with grant option;", info.Name, user) grantStr := fmt.Sprintf("grant all privileges on `%s`.* to %s", info.Name, user)
if info.Name == "*" { if info.Name == "*" {
grantStr = fmt.Sprintf("grant all privileges on *.* to %s with grant option;", user) grantStr = fmt.Sprintf("grant all privileges on *.* to %s", user)
} }
if strings.HasPrefix(info.Version, "5.7") || strings.HasPrefix(info.Version, "5.6") { if strings.HasPrefix(info.Version, "5.7") || strings.HasPrefix(info.Version, "5.6") {
grantStr = fmt.Sprintf("%s identified by '%s' with grant option;", grantStr, info.Password) grantStr = fmt.Sprintf("%s identified by '%s' with grant option;", grantStr, info.Password)
} else {
grantStr = grantStr + " with grant option;"
} }
if err := r.ExecSQL(grantStr, info.Timeout); err != nil { if err := r.ExecSQL(grantStr, info.Timeout); err != nil {
_ = r.Delete(DeleteInfo{ _ = r.Delete(DeleteInfo{

View File

@ -75,12 +75,14 @@ func (r *Remote) CreateUser(info CreateInfo, withDeleteDB bool) error {
} }
return err return err
} }
grantStr := fmt.Sprintf("grant all privileges on `%s`.* to %s with grant option;", info.Name, user) grantStr := fmt.Sprintf("grant all privileges on `%s`.* to %s", info.Name, user)
if info.Name == "*" { if info.Name == "*" {
grantStr = fmt.Sprintf("grant all privileges on *.* to %s with grant option;", user) grantStr = fmt.Sprintf("grant all privileges on *.* to %s", user)
} }
if strings.HasPrefix(info.Version, "5.7") || strings.HasPrefix(info.Version, "5.6") { if strings.HasPrefix(info.Version, "5.7") || strings.HasPrefix(info.Version, "5.6") {
grantStr = fmt.Sprintf("%s identified by '%s' with grant option;", grantStr, info.Password) grantStr = fmt.Sprintf("%s identified by '%s' with grant option;", grantStr, info.Password)
} else {
grantStr = grantStr + " with grant option;"
} }
if err := r.ExecSQL(grantStr, info.Timeout); err != nil { if err := r.ExecSQL(grantStr, info.Timeout); err != nil {
if withDeleteDB { if withDeleteDB {