Mysql – Access denied for user ‘me’@’localhost’ (using password: NO)

authenticationMySQLpermissions

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?

Best Answer

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.