Skip to content

Commit 600b769

Browse files
authored
fix: Fix the mysql root account permission switchover exception (#8378)
1 parent e7670f9 commit 600b769

File tree

3 files changed

+32
-26
lines changed

3 files changed

+32
-26
lines changed

Diff for: backend/utils/mysql/client/local.go

+12-13
Original file line numberDiff line numberDiff line change
@@ -188,19 +188,18 @@ func (r *Local) ChangeAccess(info AccessChangeInfo) error {
188188
info.Name = "*"
189189
info.Password = r.Password
190190
}
191-
if info.Permission == info.OldPermission {
192-
return nil
193-
}
194-
if err := r.Delete(DeleteInfo{
195-
Version: info.Version,
196-
Username: info.Username,
197-
Permission: info.OldPermission,
198-
ForceDelete: true,
199-
Timeout: 300}); err != nil {
200-
return err
201-
}
202-
if info.Username == "root" {
203-
return nil
191+
if info.Permission != info.OldPermission {
192+
if err := r.Delete(DeleteInfo{
193+
Version: info.Version,
194+
Username: info.Username,
195+
Permission: info.OldPermission,
196+
ForceDelete: true,
197+
Timeout: 300}); err != nil {
198+
return err
199+
}
200+
if info.Username == "root" {
201+
return nil
202+
}
204203
}
205204
if err := r.CreateUser(CreateInfo{
206205
Name: info.Name,

Diff for: backend/utils/mysql/client/remote.go

+12-13
Original file line numberDiff line numberDiff line change
@@ -199,19 +199,18 @@ func (r *Remote) ChangeAccess(info AccessChangeInfo) error {
199199
info.Name = "*"
200200
info.Password = r.Password
201201
}
202-
if info.Permission == info.OldPermission {
203-
return nil
204-
}
205-
if err := r.Delete(DeleteInfo{
206-
Version: info.Version,
207-
Username: info.Username,
208-
Permission: info.OldPermission,
209-
ForceDelete: true,
210-
Timeout: 300}); err != nil {
211-
return err
212-
}
213-
if info.Username == "root" {
214-
return nil
202+
if info.Permission != info.OldPermission {
203+
if err := r.Delete(DeleteInfo{
204+
Version: info.Version,
205+
Username: info.Username,
206+
Permission: info.OldPermission,
207+
ForceDelete: true,
208+
Timeout: 300}); err != nil {
209+
return err
210+
}
211+
if info.Username == "root" {
212+
return nil
213+
}
215214
}
216215
if err := r.CreateUser(CreateInfo{
217216
Name: info.Name,

Diff for: frontend/src/views/database/mysql/password/index.vue

+8
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ const changeVisible = ref(false);
7474
type FormInstance = InstanceType<typeof ElForm>;
7575
const changeFormRef = ref<FormInstance>();
7676
const title = ref();
77+
const oldPrivilege = ref();
78+
const oldPrivilegeIPs = ref();
7779
const changeForm = reactive({
7880
id: 0,
7981
from: '',
@@ -124,6 +126,8 @@ const acceptParams = (params: DialogProps): void => {
124126
changeForm.privilegeIPs = params.privilegeIPs;
125127
changeForm.value = params.value;
126128
changeVisible.value = true;
129+
oldPrivilege.value = params.privilege;
130+
oldPrivilegeIPs.value = params.privilegeIPs;
127131
};
128132
const emit = defineEmits<{ (e: 'search'): void }>();
129133
@@ -167,6 +171,10 @@ const submitChangeInfo = async (formEl: FormInstance | undefined) => {
167171
}
168172
return;
169173
}
174+
if (changeForm.privilege === oldPrivilege.value && changeForm.privilegeIPs === oldPrivilegeIPs.value) {
175+
changeVisible.value = false;
176+
return;
177+
}
170178
if (changeForm.privilege !== 'ip') {
171179
param.value = changeForm.privilege;
172180
} else {

0 commit comments

Comments
 (0)