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

feat: 修改根据版本区分mysql语句

This commit is contained in:
zhengkunwang223 2022-10-10 15:10:53 +08:00
parent e58e5cef0d
commit 19f9c4635b
2 changed files with 18 additions and 10 deletions

View File

@ -46,21 +46,26 @@ func execDockerCommand(database model.Database, dbInstall model.AppInstall, op D
Auth: auth,
DbParam: dbConfig,
}
_, err := cmd.Exec(getSqlStr(database.Key, op, execConfig))
_, err := cmd.Exec(getSqlStr(database.Key, dbInstall.Version, op, execConfig))
if err != nil {
return err
}
return nil
}
func getSqlStr(key string, operate DatabaseOp, exec dto.ContainerExec) string {
func getSqlStr(key, version string, operate DatabaseOp, exec dto.ContainerExec) string {
var str string
param := exec.DbParam
switch key {
case "mysql":
if operate == Add {
str = fmt.Sprintf("docker exec -i %s mysql -uroot -p%s -e \"CREATE USER '%s'@'%%' IDENTIFIED BY '%s';\" -e \"create database %s;\" -e \"GRANT ALL ON %s.* TO '%s'@'%%' IDENTIFIED BY '%s';\"",
exec.ContainerName, exec.Auth.RootPassword, param.DbUser, param.Password, param.DbName, param.DbName, param.DbUser, param.Password)
if common.CompareVersion(version, "8.0") {
str = fmt.Sprintf("docker exec -i %s mysql -uroot -p%s -e \"CREATE USER '%s'@'%%' IDENTIFIED BY '%s';\" -e \"create database %s;\" -e \"GRANT ALL ON %s.* TO '%s'@'%%';\" -e \"FLUSH PRIVILEGES;\"",
exec.ContainerName, exec.Auth.RootPassword, param.DbUser, param.Password, param.DbName, param.DbName, param.DbUser)
} else {
str = fmt.Sprintf("docker exec -i %s mysql -uroot -p%s -e \"CREATE USER '%s'@'%%' IDENTIFIED BY '%s';\" -e \"create database %s;\" -e \"GRANT ALL ON %s.* TO '%s'@'%%' IDENTIFIED BY '%s';\" -e \"FLUSH PRIVILEGES;\"",
exec.ContainerName, exec.Auth.RootPassword, param.DbUser, param.Password, param.DbName, param.DbName, param.DbUser, param.Password)
}
}
if operate == Delete {
str = fmt.Sprintf("docker exec -i %s mysql -uroot -p%s -e \"drop database %s;\" -e \"drop user %s;\" ",

View File

@ -32,10 +32,13 @@
<el-tag type="error">{{ row.status }}</el-tag>
</template>
</el-popover>
<el-icon v-if="row.status === 'Installing'" class="is-loading">
<Loading />
</el-icon>
<el-tag v-else>{{ row.status }}</el-tag>
<el-tag v-else>
<el-icon v-if="row.status === 'Installing'" class="is-loading">
<Loading />
</el-icon>
{{ row.status }}
</el-tag>
</template>
</el-table-column>
<el-table-column
@ -90,7 +93,7 @@
<script lang="ts" setup>
import { GetAppInstalled, InstalledOp, SyncInstalledApp, GetAppUpdateVersions } from '@/api/modules/app';
import { onBeforeMount, onMounted, reactive, ref } from 'vue';
import { onMounted, onUnmounted, reactive, ref } from 'vue';
import ComplexTable from '@/components/complex-table/index.vue';
import { dateFromat } from '@/utils/util';
import i18n from '@/lang';
@ -254,7 +257,7 @@ onMounted(() => {
}, 1000 * 8);
});
onBeforeMount(() => {
onUnmounted(() => {
clearInterval(Number(timer));
});
</script>