{"record":{"id":"d0699844545971ad","repo":"vitessio/vitess","slug":"error-droppping-database-q-w","errorCode":null,"errorMessage":"error droppping database %q: %w","messagePattern":"error droppping database %q: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/mysqlctl/mysqlshellbackupengine.go","lineNumber":629,"sourceCode":"\nfunc cleanupMySQL(ctx context.Context, params RestoreParams, shouldDeleteUsers bool) error {\n\tparams.Logger.Infof(\"Cleaning up MySQL ahead of a restore\")\n\tresult, err := params.Mysqld.FetchSuperQuery(ctx, \"SHOW DATABASES\")\n\tif err != nil {\n\t\treturn err\n\t}\n\n\t// drop all databases\n\tfor _, row := range result.Rows {\n\t\tdbName := row[0].ToString()\n\t\tif slices.Contains(internalDBs, dbName) {\n\t\t\tcontinue // not dropping internal DBs\n\t\t}\n\n\t\tparams.Logger.Infof(\"Dropping DB %q\", dbName)\n\t\terr = params.Mysqld.ExecuteSuperQuery(ctx, fmt.Sprintf(\"DROP DATABASE IF EXISTS `%s`\", row[0].ToString()))\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"error droppping database %q: %w\", row[0].ToString(), err)\n\t\t}\n\t}\n\n\tif shouldDeleteUsers {\n\t\t// get current user\n\t\tvar currentUser string\n\t\tresult, err = params.Mysqld.FetchSuperQuery(ctx, \"SELECT user()\")\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"error fetching current user: %w\", err)\n\t\t}\n\n\t\tfor _, row := range result.Rows {\n\t\t\tcurrentUser = row[0].ToString()\n\t\t}\n\n\t\t// drop all users except reserved ones\n\t\tresult, err = params.Mysqld.FetchSuperQuery(ctx, \"SELECT user, host FROM mysql.user\")\n\t\tif err != nil {","sourceCodeStart":611,"sourceCodeEnd":647,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/mysqlctl/mysqlshellbackupengine.go#L611-L647","documentation":"During restore, cleanupMySQL drops all non-internal databases found on the target before the mysql-shell load. This error wraps a failure of the `DROP DATABASE IF EXISTS` super-query for a given database name.","triggerScenarios":"ExecuteRestore -> cleanupMySQL when params.Mysqld.ExecuteSuperQuery(\"DROP DATABASE IF EXISTS `name`\") fails for one of the enumerated databases (returned by SHOW DATABASES filtering out internal DBs).","commonSituations":"Insufficient privileges (DROP not granted to the DBA user); database in use / locked by active connections; disk or replication issues; read-only mode (super_read_only) preventing DDL.","solutions":["Check the DBA user has DROP privileges and the server is not in super_read_only mode","Kill active connections holding the database open, then retry the restore","Inspect the wrapped inner error (%w) for the underlying MySQL error code and address it"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// before restore: verify drop rights and read-only state\nqr, err := mysqld.FetchSuperQuery(ctx, \"SELECT @@read_only | @@super_read_only\")\n// expect 0; also ensure DBA user has DROP privilege","typeGuard":null,"tryCatchPattern":"if _, err := engine.ExecuteRestore(ctx, params, backupDir); err != nil {\n    var dbErr mysql.Err // or inspect the wrapped %w error\n    if errors.As(err, &dbErr) {\n        log.Error(\"restore cleanup failed dropping database\", slog.Any(\"error\", err))\n    }\n}","preventionTips":["Grant the DBA user DROP privilege on all application databases","Disable read_only / super_read_only before restore","Ensure no long-lived connections hold locks on the databases being dropped"],"tags":["mysql-shell","backup-restore","drop-database"],"backgroundTag":"mysql-ddl-permission-denied","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}