Reputation: 338
I entered the following:
mysql> grant all on DBNAME.* to 'root@localhost' identified by 'MYROOTPWD';
Then I quit out of mysql and did some shell stuff. Now when I try to use mysql it fails with
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
I'm not mistyping the password; I can see it in the grant command a few lines up in my terminal. I've tried a bunch of the previous answers on this topic without success.
What did I do wrong? Sure, I can reset the root password and move on, but I want to know my mistake so I never repeat it.
UPDATE: No, I didn't flush privileges. Apparently I have misunderstood what that does. Why is my previously-existing ability (to use mysql at all) not working?
Upvotes: 0
Views: 254
Reputation: 108400
MySQL user should be identified by separate username and hostname, in the GRANT statement:
> grant ... to 'root'@'localhost' ...
^ ^
(Note the quotes around the username and around the hostname.) A MySQL user is identified by username and a hostname. If you just have a single quoted string, MySQL uses that as a the username and assumes a hostname. Check the mysql.db table, likely you have a row with User
column containing root@localhost
.
Upvotes: 2