ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
The login password has been wrong
Possible Causes
Caused by different host passwords for the same user
Solution
- Add skip-grant-tables under [mysqld] in the /etc/my.cnf file without logging in
- Restart mysql service
service mysql restart
- Query host, user, authentication_string
select host,user,authentication_string from user where user='root';
It can be seen from the figure that the local and% authentication_string of the same user are different
Explain that the password used by the root user on this machine is different from the password used elsewhere
% Represents all hosts
But setting localhost alone is different from other passwords (under the same user)
The password of other host is also different from the password of% (other) (under the same user)
Find the problem, change the password
Modify the password of this machine
set password for 'root'@'localhost' = password('123456');
Modify the passwords of all hosts
set password for 'root'@'%' = password('123456');
The example password is too simple, please do not imitate
If an error occurs when executing the above set password command ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
First execute flush privileges;
If you can log in to the user's mysql in other places, it is the% password. For example, you can log in in the window visual database connection tool navicate, then you can also directly set user='root' in the user table of the user database in mysql, and the host is localhost. Delete that record, leaving only the record with user='root' and host='%'
delete from user where user='root' and host='localhost';