ERROR 1044 (42000): Access denied for user ''@ 'localhost' to database 'mysql' solution: 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. Www.2cto.com Method 1: 1. disable mysql # service mysqld stop2. block permission # mysqld_safe -- skip-grant-table: Starting demo from ..... 3. start a new terminal and enter # mysql-u root 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 mysql> \ q method 2 will appear: 1. disable mysql # service mysqld stop2. block permission # mysqld_safe -- skip-grant-table: Starting demo from ..... www.2cto.com 3. start a new terminal and enter # mysql-u root mysql> delete from user where USER = ''; mysql> flush privileges; // remember this sentence, otherwise, if you close the previous terminal, the original error mysql> \ q will appear.