0

I am am trying to learn mysql 101. Doing so, I broke my ability to login as root.

At first I could simply connect to mysql by running

sudo mysql

In an attempt to alleviate a problem, I thoughtlessly copy and pasted some sql into the mysql prompt.

Specifically...

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';

Now when I try to log in using sudo mysql, I get the error...

Access denied for user 'me'@'localhost' (using password: NO)

What exactly did I do, and how can I rectify it?

1
  • What version of MySQL?
    – Rick James
    Commented Oct 6, 2019 at 18:43

1 Answer 1

1

Now you can probably login by

sudo mysql -u root -p

and entering the password from your ALTER USER statement when prompted.

Once you're in the console again you can reset the password to empty like:

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '';

And it should start to allow you with just sudo mysql as before.

1
  • 1
    I disagree with your ALTER USER statement - this will allow everyone to connect as root without a password. It sounds like the original root user was configured to use the password-less, but secure socket authentication plugin - this is why they had to do sudo mysql.
    – dbdemon
    Commented Dec 11, 2019 at 8:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.