Tip: ERROR 1044 (42000): Access denied for user ''@ 'localhost' to database 'mysql '. This problem also occurred two days ago. I found a popular method on the Internet (see method 1. I tried this again today, but I was not sure. After searching for it online for half a day, I finally found that there is an account with a blank username in the user table of the mysql database, that is, an anonymous account, root is used for logon, but Anonymous logon is actually performed. You can see the '@ 'localhost' in the error message. For the solution, see method 2.
Method 1:
1. Disable mysql
# Service mysqld stop
2. Block Permissions
# Mysqld_safe -- skip-grant-table
The screen displays: Starting demo from .....
3. Start a new terminal Input
# Mysql-u root mysql
Mysql> UPDATE user SET Password = PASSWORD ('newpassword') where USER = 'root ';
Mysql> flush privileges; // remember this sentence. Otherwise, if you close the previous terminal, the original error will occur.
Mysql> \ q
Method 2:
1. Disable mysql
# Service mysqld stop
2. Block Permissions
# Mysqld_safe -- skip-grant-table
The screen displays: Starting demo from .....
3. Start a new terminal Input
# Mysql-u root mysql
Mysql> delete from user where USER = '';
Mysql> flush privileges; // remember this sentence. Otherwise, if you close the previous terminal, the original error will occur.
Mysql> \ q