1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-01-31 22:18:07 +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, Auth: auth,
DbParam: dbConfig, DbParam: dbConfig,
} }
_, err := cmd.Exec(getSqlStr(database.Key, op, execConfig)) _, err := cmd.Exec(getSqlStr(database.Key, dbInstall.Version, op, execConfig))
if err != nil { if err != nil {
return err return err
} }
return nil 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 var str string
param := exec.DbParam param := exec.DbParam
switch key { switch key {
case "mysql": case "mysql":
if operate == Add { 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';\"", if common.CompareVersion(version, "8.0") {
exec.ContainerName, exec.Auth.RootPassword, param.DbUser, param.Password, param.DbName, param.DbName, param.DbUser, param.Password) 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 { if operate == Delete {
str = fmt.Sprintf("docker exec -i %s mysql -uroot -p%s -e \"drop database %s;\" -e \"drop user %s;\" ", 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> <el-tag type="error">{{ row.status }}</el-tag>
</template> </template>
</el-popover> </el-popover>
<el-icon v-if="row.status === 'Installing'" class="is-loading">
<Loading /> <el-tag v-else>
</el-icon> <el-icon v-if="row.status === 'Installing'" class="is-loading">
<el-tag v-else>{{ row.status }}</el-tag> <Loading />
</el-icon>
{{ row.status }}
</el-tag>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column <el-table-column
@ -90,7 +93,7 @@
<script lang="ts" setup> <script lang="ts" setup>
import { GetAppInstalled, InstalledOp, SyncInstalledApp, GetAppUpdateVersions } from '@/api/modules/app'; 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 ComplexTable from '@/components/complex-table/index.vue';
import { dateFromat } from '@/utils/util'; import { dateFromat } from '@/utils/util';
import i18n from '@/lang'; import i18n from '@/lang';
@ -254,7 +257,7 @@ onMounted(() => {
}, 1000 * 8); }, 1000 * 8);
}); });
onBeforeMount(() => { onUnmounted(() => {
clearInterval(Number(timer)); clearInterval(Number(timer));
}); });
</script> </script>