This article has been included in: Tip: ERROR 1044 (42000): Access denied for user "@ ' localhost ' to database ' MySQL '. The first two days also appeared this problem, online find a more popular method (see method one), done. Today again with this try, but do not make, in the Internet to find a half-day, finally found that because of the MySQL database user table, there is a username is empty account is anonymous account, resulting in the time of login is the root, but the actual is anonymous login, through the error prompt "@" LocalHost ' can be seen, so the solution to see method two.
Method One: 1. Turn off MySQL # service mysqld stop 2. Mask Permissions # Mysqld_safe--skip-grant-table screen appears: Starting Demo from ... 3. Newly opened a terminal input # mysql-u root mysql mysql> UPDATE user SET Password=password (' NewPassword ') where user= ' root '; Mysql> FLUSH privileges;//Remember to say this, otherwise if you close the previous terminal, the original error will appear mysql> \q
Method Two: 1. Turn off MySQL # service mysqld stop 2. Mask Permissions # Mysqld_safe--skip-grant-table screen appears: Starting Demo from ... 3. Newly opened a terminal input # mysql-u root MySQL mysql> delete from user where user= '; Mysql> FLUSH privileges;//Remember to say this, otherwise if you close the previous terminal, the original error will appear mysql> \q
ERROR 1044 (42000): Access denied for user "@ ' localhost ' to database ' MySQL '