{"record":{"id":"48b73e3c218eba71","repo":"vitessio/vitess","slug":"error-fetching-current-user-w","errorCode":null,"errorMessage":"error fetching current user: %w","messagePattern":"error fetching current user: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/mysqlctl/mysqlshellbackupengine.go","lineNumber":638,"sourceCode":"\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 {\n\t\t\treturn err\n\t\t}\n\n\t\tfor _, row := range result.Rows {\n\t\t\tuser := fmt.Sprintf(\"%s@%s\", row[0].ToString(), row[1].ToString())\n\n\t\t\tif user == currentUser {\n\t\t\t\tcontinue // we don't drop the current user\n\t\t\t}","sourceCodeStart":620,"sourceCodeEnd":656,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/mysqlctl/mysqlshellbackupengine.go#L620-L656","documentation":"When loadFlags request loadUsers deletion (shouldDeleteUsers), cleanupMySQL first runs `SELECT user()` to identify the current connection's user so it isn't dropped. This error wraps a failure of that fetch.","triggerScenarios":"ExecuteRestore -> cleanupMySQL with shouldDeleteUsers=true when params.Mysqld.FetchSuperQuery(ctx, \"SELECT user()\") returns an error (connection dropped or query rejected).","commonSituations":"Connection to mysqld lost between cleanup steps; DBA user lacking privileges to execute SELECT user() via the super-query path; server shutting down mid-restore.","solutions":["Verify mysqld is still up and the super-query connection is healthy, then retry","Check the wrapped inner error for the root cause (auth, connection, permissions)","Avoid enabling user deletion (loadUsers flag) if the restore only needs schema/data cleanup"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// health-check the super-query connection before restore\nif err := mysqld.ExecuteSuperQuery(ctx, \"SELECT 1\"); err != nil {\n    log.Warn(\"mysqld connection unhealthy before restore\", slog.Any(\"error\", err))\n}","typeGuard":null,"tryCatchPattern":"if _, err := engine.ExecuteRestore(ctx, params, backupDir); err != nil {\n    if strings.Contains(err.Error(), \"error fetching current user\") {\n        // check connectivity/auth, then retry restore\n    }\n}","preventionTips":["Avoid enabling user deletion unless it is genuinely needed","Monitor connection stability between tablet and mysqld during restores","Confirm the DBA account can run SELECT user()"],"tags":["mysql-shell","backup-restore","user-management"],"backgroundTag":"mysql-connection-failed","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}