1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-01-31 22:18:07 +08:00

fix: 兼容 mysql 5.7.42 (#1286)

This commit is contained in:
ssongliu 2023-06-08 11:00:12 +08:00 committed by GitHub
parent 203af988fa
commit 6a717b2517
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 5 deletions

View File

@ -195,7 +195,7 @@ func (u *MysqlService) ChangePassword(info dto.ChangeDBInfo) error {
} }
passwordChangeCMD := fmt.Sprintf("set password for '%s'@'%s' = password('%s')", mysql.Username, mysql.Permission, info.Value) passwordChangeCMD := fmt.Sprintf("set password for '%s'@'%s' = password('%s')", mysql.Username, mysql.Permission, info.Value)
if app.Version != "5.7.39" { if !strings.HasPrefix(app.Version, "5.7") {
passwordChangeCMD = fmt.Sprintf("ALTER USER '%s'@'%s' IDENTIFIED WITH mysql_native_password BY '%s';", mysql.Username, mysql.Permission, info.Value) passwordChangeCMD = fmt.Sprintf("ALTER USER '%s'@'%s' IDENTIFIED WITH mysql_native_password BY '%s';", mysql.Username, mysql.Permission, info.Value)
} }
if info.ID != 0 { if info.ID != 0 {
@ -230,7 +230,7 @@ func (u *MysqlService) ChangePassword(info dto.ChangeDBInfo) error {
for _, host := range hosts { for _, host := range hosts {
if host == "%" || host == "localhost" { if host == "%" || host == "localhost" {
passwordRootChangeCMD := fmt.Sprintf("set password for 'root'@'%s' = password('%s')", host, info.Value) passwordRootChangeCMD := fmt.Sprintf("set password for 'root'@'%s' = password('%s')", host, info.Value)
if app.Version != "5.7.39" { if !strings.HasPrefix(app.Version, "5.7") {
passwordRootChangeCMD = fmt.Sprintf("alter user 'root'@'%s' identified with mysql_native_password BY '%s';", host, info.Value) passwordRootChangeCMD = fmt.Sprintf("alter user 'root'@'%s' identified with mysql_native_password BY '%s';", host, info.Value)
} }
if err := excuteSql(app.ContainerName, app.Password, passwordRootChangeCMD); err != nil { if err := excuteSql(app.ContainerName, app.Password, passwordRootChangeCMD); err != nil {
@ -347,7 +347,7 @@ func (u *MysqlService) UpdateVariables(updates []dto.MysqlVariablesUpdate) error
group := "[mysqld]" group := "[mysqld]"
for _, info := range updates { for _, info := range updates {
if app.Version != "5.7.39" { if !strings.HasPrefix(app.Version, "5.7") {
if info.Param == "query_cache_size" { if info.Param == "query_cache_size" {
continue continue
} }
@ -495,7 +495,7 @@ func (u *MysqlService) createUser(app *repo.RootInfo, req dto.MysqlDBCreate) err
if req.Name == "*" { if req.Name == "*" {
grantStr = fmt.Sprintf("grant all privileges on *.* to %s", user) grantStr = fmt.Sprintf("grant all privileges on *.* to %s", user)
} }
if app.Version == "5.7.39" { if strings.HasPrefix(app.Version, "5.7") {
grantStr = fmt.Sprintf("%s identified by '%s' with grant option;", grantStr, req.Password) grantStr = fmt.Sprintf("%s identified by '%s' with grant option;", grantStr, req.Password)
} }
if err := excSQL(app.ContainerName, app.Password, grantStr); err != nil { if err := excSQL(app.ContainerName, app.Password, grantStr); err != nil {

View File

@ -76,7 +76,7 @@
</el-input> </el-input>
<span class="input-help">{{ $t('database.readRndBufferSizeHelper') }}</span> <span class="input-help">{{ $t('database.readRndBufferSizeHelper') }}</span>
</el-form-item> </el-form-item>
<el-form-item v-if="mysqlVersion === '5.7.39'" label="query_cache_size" prop="query_cache_size"> <el-form-item v-if="showCacheSize" label="query_cache_size" prop="query_cache_size">
<el-input clearable v-model.number="mysqlVariables.query_cache_size"> <el-input clearable v-model.number="mysqlVariables.query_cache_size">
<template #append>MB</template> <template #append>MB</template>
</el-input> </el-input>
@ -292,6 +292,9 @@ const onSaveVariables = async () => {
}); });
}; };
const showCacheSize = () => {
return mysqlVersion.value.startsWith('5.7');
};
defineExpose({ defineExpose({
acceptParams, acceptParams,
}); });