diff --git a/backend/app/api/v1/database_mysql.go b/backend/app/api/v1/database_mysql.go index 1a8336ca3..ee5d70f29 100644 --- a/backend/app/api/v1/database_mysql.go +++ b/backend/app/api/v1/database_mysql.go @@ -201,6 +201,16 @@ func (b *BaseApi) LoadBaseinfo(c *gin.Context) { helper.SuccessWithData(c, data) } +func (b *BaseApi) LoadRemoteAccess(c *gin.Context) { + isRemote, err := mysqlService.LoadRemoteAccess() + if err != nil { + helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + return + } + + helper.SuccessWithData(c, isRemote) +} + func (b *BaseApi) LoadStatus(c *gin.Context) { data, err := mysqlService.LoadStatus() if err != nil { diff --git a/backend/app/dto/database.go b/backend/app/dto/database.go index 4d7ea5bc3..1d590aa0e 100644 --- a/backend/app/dto/database.go +++ b/backend/app/dto/database.go @@ -101,8 +101,6 @@ type DBBaseInfo struct { Name string `json:"name"` ContainerName string `json:"containerName"` Port int64 `json:"port"` - Password string `json:"password"` - RemoteConn bool `json:"remoteConn"` } type SearchDBWithPage struct { diff --git a/backend/app/service/database_mysql.go b/backend/app/service/database_mysql.go index ab7daf584..314e70532 100644 --- a/backend/app/service/database_mysql.go +++ b/backend/app/service/database_mysql.go @@ -46,6 +46,7 @@ type IMysqlService interface { LoadStatus() (*dto.MysqlStatus, error) LoadVariables() (*dto.MysqlVariables, error) LoadBaseInfo() (*dto.DBBaseInfo, error) + LoadRemoteAccess() (bool, error) } func NewIMysqlService() IMysqlService { @@ -266,6 +267,22 @@ func (u *MysqlService) Delete(id uint) error { if err := excuteSql(app.ContainerName, app.Password, fmt.Sprintf("drop database if exists %s", db.Name)); err != nil { return err } + + uploadDir := fmt.Sprintf("%s/uploads/%s/mysql/%s", constant.DefaultDataDir, app.Name, db.Name) + if _, err := os.Stat(uploadDir); err == nil { + _ = os.RemoveAll(uploadDir) + } + + localDir, err := loadLocalDir() + if err != nil { + return err + } + backupDir := fmt.Sprintf("%s/database/mysql/%s/%s", localDir, db.MysqlName, db.Name) + if _, err := os.Stat(backupDir); err == nil { + _ = os.RemoveAll(backupDir) + } + _ = backupRepo.DeleteRecord(commonRepo.WithByType("database-mysql"), commonRepo.WithByName(app.Name), backupRepo.WithByDetailName(db.Name)) + _ = mysqlRepo.Delete(context.Background(), commonRepo.WithByID(db.ID)) return nil } @@ -406,7 +423,13 @@ func (u *MysqlService) UpdateVariables(updatas []dto.MysqlVariablesUpdate) error } group := "[mysqld]" for _, info := range updatas { - files = updateMyCnf(files, group, info.Param, info.Value) + if app.Version != "5.7.39" { + if info.Param == "query_cache_size" { + continue + } + } + + files = updateMyCnf(files, group, info.Param, loadSizeUnit(info.Value)) } file, err := os.OpenFile(path, os.O_WRONLY, 0666) if err != nil { @@ -434,19 +457,26 @@ func (u *MysqlService) LoadBaseInfo() (*dto.DBBaseInfo, error) { data.ContainerName = app.ContainerName data.Name = app.Name data.Port = int64(app.Port) - data.Password = app.Password + return &data, nil +} + +func (u *MysqlService) LoadRemoteAccess() (bool, error) { + app, err := appInstallRepo.LoadBaseInfoByKey("mysql") + if err != nil { + return false, err + } hosts, err := excuteSqlForRows(app.ContainerName, app.Password, "select host from mysql.user where user='root';") if err != nil { - return nil, err + return false, err } for _, host := range hosts { if host == "%" { - data.RemoteConn = true - break + return true, nil } } - return &data, nil + + return false, nil } func (u *MysqlService) LoadVariables() (*dto.MysqlVariables, error) { @@ -633,3 +663,13 @@ func updateMyCnf(oldFiles []string, group string, param string, value interface{ } return newFiles } + +func loadSizeUnit(value int64) string { + if value > 1048576 { + return fmt.Sprintf("%dM", value/1048576) + } + if value > 1024 { + return fmt.Sprintf("%dK", value/1024) + } + return fmt.Sprintf("%d", value) +} diff --git a/backend/router/ro_database.go b/backend/router/ro_database.go index 3e7462ae7..60f3b87f9 100644 --- a/backend/router/ro_database.go +++ b/backend/router/ro_database.go @@ -35,6 +35,7 @@ func (s *DatabaseRouter) InitDatabaseRouter(Router *gin.RouterGroup) { cmdRouter.GET("/variables", baseApi.LoadVariables) cmdRouter.GET("/status", baseApi.LoadStatus) cmdRouter.GET("/baseinfo", baseApi.LoadBaseinfo) + cmdRouter.GET("/remote", baseApi.LoadRemoteAccess) cmdRouter.GET("/options", baseApi.ListDBName) cmdRouter.GET("/redis/persistence/conf", baseApi.LoadPersistenceConf) diff --git a/frontend/src/api/modules/database.ts b/frontend/src/api/modules/database.ts index 531c56069..9a34c1f01 100644 --- a/frontend/src/api/modules/database.ts +++ b/frontend/src/api/modules/database.ts @@ -47,6 +47,9 @@ export const loadMysqlVariables = () => { export const loadMysqlStatus = () => { return http.get(`/databases/status`); }; +export const loadRemoteAccess = () => { + return http.get(`/databases/remote`); +}; export const loadDBNames = () => { return http.get>(`/databases/options`); }; diff --git a/frontend/src/lang/modules/zh.ts b/frontend/src/lang/modules/zh.ts index d6ee314b7..c458a5119 100644 --- a/frontend/src/lang/modules/zh.ts +++ b/frontend/src/lang/modules/zh.ts @@ -138,6 +138,7 @@ export default { error: '失败', created: '已创建', restarting: '重启中', + unhealthy: '异常', removing: '迁移中', paused: '暂停', exited: '停止', @@ -220,6 +221,8 @@ export default { database: { create: '创建数据库', noMysql: '当前未检测到 {0} 数据库,请进入应用商店点击安装!', + mysqlBadStatus: '当前 mysql 应用状态异常,请在', + adjust: '中查看原因或修改配置', goInstall: '去安装', source: '来源', backup: '备份', diff --git a/frontend/src/views/container/compose/detail/index.vue b/frontend/src/views/container/compose/detail/index.vue index d850e8b38..ddbbc9491 100644 --- a/frontend/src/views/container/compose/detail/index.vue +++ b/frontend/src/views/container/compose/detail/index.vue @@ -1,6 +1,6 @@