I have run the following commands found here.

shell> mysql
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass'

But when I go to login as root, I can type any string as a password, and it will still let me login.

How can I enforce a password for root, and not allow anonymous users by simply typing mysql

  • Do you have authentication methods other than password enabled for root?
    – Joe W
    Oct 7, 2018 at 17:25
  • I am not sure. Just installed MySQL on a virtual machine. I'm not sure how to enable authentication methods with this DBMS.
    – crayden
    Oct 7, 2018 at 19:39

2 Answers 2


The following worked for me:

I ran through the command line wizard to set this up:
shell> mysql_secure_installation

Then entered the following:
shell> mysql
ALTER USER 'root'@'localhost' IDENTIFIED with mysql_native_password;
ALTER USER 'root'@'localhost' IDENTIFIED BY 'password';

Credit goes to this question/answer.


You wanna try this granting all users by password

Grant All Privileges ON *.* to 'USER_NAME'@'%' Identified By 'YOUR_PASSWORD'; 

  • Invalid syntax in MySQL-8.0. Also FLUSH PRIVILEGES isn't required. wanna isn't a word.
    – danblack
    Jan 21, 2022 at 0:35

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.