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. shield permission
# mysqld_safe -- skip-grant-Table
on the screen: Starting demo from .....
3. start a new terminal and enter
# 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 may occur.
mysql> \ q