Skip to content

Commit 50deda2

Browse files
authored
feat: 数据库兼容 mysql 5.6.51 版本 (1Panel-dev#1450)
1 parent 4482fa2 commit 50deda2

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

backend/app/service/database_mysql.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ func (u *MysqlService) ChangePassword(info dto.ChangeDBInfo) error {
194194
}
195195

196196
passwordChangeCMD := fmt.Sprintf("set password for '%s'@'%s' = password('%s')", mysql.Username, mysql.Permission, info.Value)
197-
if !strings.HasPrefix(app.Version, "5.7") {
197+
if !strings.HasPrefix(app.Version, "5.7") && !strings.HasPrefix(app.Version, "5.6") {
198198
passwordChangeCMD = fmt.Sprintf("ALTER USER '%s'@'%s' IDENTIFIED WITH mysql_native_password BY '%s';", mysql.Username, mysql.Permission, info.Value)
199199
}
200200
if info.ID != 0 {
@@ -229,7 +229,7 @@ func (u *MysqlService) ChangePassword(info dto.ChangeDBInfo) error {
229229
for _, host := range hosts {
230230
if host == "%" || host == "localhost" {
231231
passwordRootChangeCMD := fmt.Sprintf("set password for 'root'@'%s' = password('%s')", host, info.Value)
232-
if !strings.HasPrefix(app.Version, "5.7") {
232+
if !strings.HasPrefix(app.Version, "5.7") && !strings.HasPrefix(app.Version, "5.6") {
233233
passwordRootChangeCMD = fmt.Sprintf("alter user 'root'@'%s' identified with mysql_native_password BY '%s';", host, info.Value)
234234
}
235235
if err := excuteSql(app.ContainerName, app.Password, passwordRootChangeCMD); err != nil {
@@ -280,8 +280,14 @@ func (u *MysqlService) ChangeAccess(info dto.ChangeDBInfo) error {
280280
}
281281
for _, user := range userlist {
282282
if len(user) != 0 {
283-
if err := excuteSql(app.ContainerName, app.Password, fmt.Sprintf("drop user if exists '%s'@'%s'", mysql.Username, user)); err != nil {
284-
return err
283+
if strings.HasPrefix(app.Version, "5.6") {
284+
if err := excuteSql(app.ContainerName, app.Password, fmt.Sprintf("drop user '%s'@'%s'", mysql.Username, user)); err != nil {
285+
return err
286+
}
287+
} else {
288+
if err := excuteSql(app.ContainerName, app.Password, fmt.Sprintf("drop user if exists '%s'@'%s'", mysql.Username, user)); err != nil {
289+
return err
290+
}
285291
}
286292
}
287293
}
@@ -346,7 +352,7 @@ func (u *MysqlService) UpdateVariables(updates []dto.MysqlVariablesUpdate) error
346352

347353
group := "[mysqld]"
348354
for _, info := range updates {
349-
if !strings.HasPrefix(app.Version, "5.7") {
355+
if !strings.HasPrefix(app.Version, "5.7") && !strings.HasPrefix(app.Version, "5.6") {
350356
if info.Param == "query_cache_size" {
351357
continue
352358
}
@@ -495,7 +501,7 @@ func (u *MysqlService) createUser(container, password, version string, req dto.M
495501
if req.Name == "*" {
496502
grantStr = fmt.Sprintf("grant all privileges on *.* to %s", user)
497503
}
498-
if strings.HasPrefix(version, "5.7") {
504+
if strings.HasPrefix(version, "5.7") || strings.HasPrefix(version, "5.6") {
499505
grantStr = fmt.Sprintf("%s identified by '%s' with grant option;", grantStr, req.Password)
500506
}
501507
if err := excSQL(container, password, grantStr); err != nil {

0 commit comments

Comments
 (0)