Skip to content

Commit 9447936

Browse files
ssongliuwanghe-fit2cloud
authored andcommitted
fix: 解决获取远程数据库失败的问题 (#1974)
Refs #1925
1 parent 5e7429c commit 9447936

File tree

5 files changed

+44
-52
lines changed

5 files changed

+44
-52
lines changed

backend/utils/mysql/client/local.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ func (r *Local) ChangePassword(info PasswordChangeInfo) error {
147147
for _, user := range userlist {
148148
passwordChangeSql := fmt.Sprintf("set password for %s = password('%s')", user, info.Password)
149149
if !strings.HasPrefix(info.Version, "5.7") && !strings.HasPrefix(info.Version, "5.6") {
150-
passwordChangeSql = fmt.Sprintf("ALTER USER %s IDENTIFIED WITH mysql_native_password BY '%s';", user, info.Password)
150+
passwordChangeSql = fmt.Sprintf("alter user %s identified by '%s';", user, info.Password)
151151
}
152152
if err := r.ExecSQL(passwordChangeSql, info.Timeout); err != nil {
153153
return err
@@ -276,7 +276,7 @@ func (r *Local) SyncDB(version string) ([]SyncDBInfo, error) {
276276
From: r.From,
277277
Format: parts[1],
278278
}
279-
userLines, err := r.ExecSQLForRows(fmt.Sprintf("SELECT USER,HOST FROM mysql.DB WHERE DB = '%s'", parts[0]), 300)
279+
userLines, err := r.ExecSQLForRows(fmt.Sprintf("select user,host from mysql.db where db = '%s'", parts[0]), 300)
280280
if err != nil {
281281
return datas, err
282282
}

backend/utils/mysql/client/remote.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ func (r *Remote) Recover(info RecoverInfo) error {
263263

264264
func (r *Remote) SyncDB(version string) ([]SyncDBInfo, error) {
265265
var datas []SyncDBInfo
266-
rows, err := r.Client.Query("SELECT SCHEMA_NAME, DEFAULT_CHARACTER_SET_NAME FROM information_schema.SCHEMATA")
266+
rows, err := r.Client.Query("select schema_name, default_character_set_name from information_schema.SCHEMATA")
267267
if err != nil {
268268
return datas, err
269269
}
@@ -283,7 +283,7 @@ func (r *Remote) SyncDB(version string) ([]SyncDBInfo, error) {
283283
MysqlName: r.From,
284284
Format: charsetName,
285285
}
286-
userRows, err := r.Client.Query("SELECT USER,HOST FROM mysql.DB WHERE DB = ?", dbName)
286+
userRows, err := r.Client.Query("select user,host from mysql.db where db = ?", dbName)
287287
if err != nil {
288288
return datas, err
289289
}

frontend/src/routers/modules/database.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,16 @@ const databaseRouter = {
2727
requiresAuth: false,
2828
},
2929
},
30+
{
31+
path: 'mysql/setting',
32+
name: 'MySQL-Setting',
33+
component: () => import('@/views/database/mysql/setting/index.vue'),
34+
hidden: true,
35+
meta: {
36+
activeMenu: '/databases',
37+
requiresAuth: false,
38+
},
39+
},
3040
{
3141
path: 'mysql/remote',
3242
name: 'MySQL-Remote',

frontend/src/views/database/mysql/index.vue

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
></AppStatus>
1212
</template>
1313

14-
<template v-if="!isOnSetting" #search>
14+
<template #search>
1515
<el-select v-model="paginationConfig.from" @change="search()">
1616
<template #prefix>{{ $t('commons.table.type') }}</template>
1717
<el-option-group>
@@ -28,7 +28,7 @@
2828
</el-select>
2929
</template>
3030

31-
<template #toolbar v-if="!isOnSetting">
31+
<template #toolbar>
3232
<el-row>
3333
<el-col :xs="24" :sm="20" :md="20" :lg="20" :xl="20">
3434
<el-button
@@ -77,7 +77,7 @@
7777
</el-col>
7878
</el-row>
7979
</template>
80-
<template #main v-if="(mysqlIsExist && !isOnSetting) || !isLocal()">
80+
<template #main v-if="mysqlIsExist || !isLocal()">
8181
<ComplexTable
8282
:pagination-config="paginationConfig"
8383
@sort-change="search"
@@ -162,14 +162,10 @@
162162
</LayoutContent>
163163
</div>
164164

165-
<el-card
166-
v-if="mysqlStatus != 'Running' && !isOnSetting && mysqlIsExist && !loading && maskShow && isLocal"
167-
class="mask-prompt"
168-
>
165+
<el-card v-if="mysqlStatus != 'Running' && mysqlIsExist && !loading && maskShow && isLocal" class="mask-prompt">
169166
<span>{{ $t('commons.service.serviceNotStarted', ['MySQL']) }}</span>
170167
</el-card>
171168

172-
<Setting ref="settingRef" style="margin-top: 20px" />
173169
<el-dialog
174170
v-model="phpVisiable"
175171
:title="$t('app.checkTitle')"
@@ -208,7 +204,6 @@ import DeleteDialog from '@/views/database/mysql/delete/index.vue';
208204
import PasswordDialog from '@/views/database/mysql/password/index.vue';
209205
import RootPasswordDialog from '@/views/database/mysql/conn/index.vue';
210206
import AppResources from '@/views/database/mysql/check/index.vue';
211-
import Setting from '@/views/database/mysql/setting/index.vue';
212207
import AppStatus from '@/components/app-status/index.vue';
213208
import Backups from '@/components/backup/index.vue';
214209
import UploadDialog from '@/components/upload/index.vue';
@@ -238,7 +233,6 @@ const maskShow = ref(true);
238233
const dbOptions = ref<Array<Database.RemoteDBOption>>([]);
239234
240235
const mysqlName = ref();
241-
const isOnSetting = ref<boolean>();
242236
243237
const checkRef = ref();
244238
const deleteRef = ref();
@@ -292,15 +286,8 @@ function isLocal() {
292286
293287
const passwordRef = ref();
294288
295-
const settingRef = ref();
296289
const onSetting = async () => {
297-
isOnSetting.value = true;
298-
let params = {
299-
status: mysqlStatus.value,
300-
mysqlName: mysqlName.value,
301-
mysqlVersion: mysqlVersion.value,
302-
};
303-
settingRef.value!.acceptParams(params);
290+
router.push({ name: 'MySQL-Setting' });
304291
};
305292
306293
const search = async (column?: any) => {

frontend/src/views/database/mysql/setting/index.vue

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
<template>
2-
<div v-show="onSetting" v-loading="loading">
3-
<LayoutContent :title="'MySQL ' + $t('commons.button.set')" :reload="true">
4-
<template #buttons>
2+
<div v-loading="loading">
3+
<LayoutContent>
4+
<template #title>
5+
<back-button name="MySQL" :header="'MySQL ' + $t('commons.button.set')" />
6+
</template>
7+
8+
<template #toolbar>
59
<el-button type="primary" :plain="activeName !== 'conf'" @click="jumpToConf">
610
{{ $t('database.confChange') }}
711
</el-button>
@@ -115,12 +119,12 @@ import Status from '@/views/database/mysql/setting/status/index.vue';
115119
import Variables from '@/views/database/mysql/setting/variables/index.vue';
116120
import SlowLog from '@/views/database/mysql/setting/slow-log/index.vue';
117121
import ConfirmDialog from '@/components/confirm-dialog/index.vue';
118-
import { reactive, ref } from 'vue';
122+
import { onMounted, reactive, ref } from 'vue';
119123
import { Codemirror } from 'vue-codemirror';
120124
import { javascript } from '@codemirror/lang-javascript';
121125
import { oneDark } from '@codemirror/theme-one-dark';
122126
import { loadDatabaseFile, loadMysqlBaseInfo, loadMysqlVariables, updateMysqlConfByFile } from '@/api/modules/database';
123-
import { ChangePort, GetAppDefaultConfig } from '@/api/modules/app';
127+
import { ChangePort, CheckAppInstalled, GetAppDefaultConfig } from '@/api/modules/app';
124128
import { Rules } from '@/global/form-rules';
125129
import i18n from '@/lang';
126130
import { MsgSuccess } from '@/utils/message';
@@ -146,34 +150,12 @@ const statusRef = ref();
146150
const variablesRef = ref();
147151
const slowLogRef = ref();
148152
149-
const onSetting = ref<boolean>(false);
150153
const mysqlName = ref();
151154
const mysqlStatus = ref();
152155
const mysqlVersion = ref();
153156
const variables = ref();
154157
155-
interface DialogProps {
156-
mysqlName: string;
157-
mysqlVersion: string;
158-
status: string;
159-
}
160-
161158
const dialogContainerLogRef = ref();
162-
const acceptParams = (props: DialogProps): void => {
163-
onSetting.value = true;
164-
mysqlStatus.value = props.status;
165-
mysqlVersion.value = props.mysqlVersion;
166-
loadBaseInfo();
167-
if (mysqlStatus.value === 'Running') {
168-
loadVariables();
169-
loadSlowLogs();
170-
statusRef.value!.acceptParams({ mysqlName: props.mysqlName });
171-
}
172-
};
173-
const onClose = (): void => {
174-
onSetting.value = false;
175-
};
176-
177159
const jumpToConf = async () => {
178160
activeName.value = 'conf';
179161
loadMysqlConf();
@@ -303,8 +285,21 @@ const loadMysqlConf = async () => {
303285
mysqlConf.value = res.data;
304286
};
305287
306-
defineExpose({
307-
acceptParams,
308-
onClose,
288+
const onLoadInfo = async () => {
289+
await CheckAppInstalled('mysql').then((res) => {
290+
mysqlName.value = res.data.name;
291+
mysqlStatus.value = res.data.status;
292+
mysqlVersion.value = res.data.version;
293+
loadBaseInfo();
294+
if (mysqlStatus.value === 'Running') {
295+
loadVariables();
296+
loadSlowLogs();
297+
statusRef.value!.acceptParams({ mysqlName: mysqlName.value });
298+
}
299+
});
300+
};
301+
302+
onMounted(() => {
303+
onLoadInfo();
309304
});
310305
</script>

0 commit comments

Comments
 (0)