Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue-98: Fixed determination of whether root user exists or not #99

Merged
merged 1 commit into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/moco-agent/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ func initializeMySQLForMOCO(ctx context.Context, socketPath string, logger logr.
if err == nil {
break
}
if server.IsAccessDenied(err) {
if server.UserNotExists(err) {
// There is no passwordless 'root'@'localhost' account.
// It means the initialization has been completed.
return nil
Expand Down
9 changes: 7 additions & 2 deletions server/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,14 @@ func GetMySQLConnLocalSocket(user, password, socket string) (*sqlx.DB, error) {
return db, nil
}

func IsAccessDenied(err error) bool {
func UserNotExists(err error) bool {
// For security reason, error messages are randomly output when a user does not exist.
// https://github.com/mysql/mysql-server/commit/b40001faf6229dca668c9d03ba75c451f999c9f5
// This function assumes the user does not exist when the following message is output:
// ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
// ERROR 1524 (HY000): Plugin 'mysql_native_password' is not loaded
var merr *mysql.MySQLError
if errors.As(err, &merr) && merr.Number == 1045 {
if errors.As(err, &merr) && (merr.Number == 1045 || merr.Number == 1524) {
return true
}

Expand Down