Just refer to this.
1. Problems
Sometimes when we log in to Mysql and enter the password, this happens
mysql -u root -p
Enter Password > 'Password'
错误:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
Or: Error: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
Two, the solution
Modify the my.in/my.cnf configuration file
Enter the mysql installation directory
edit my.ini
Add skip-grant-tables under [mysqld] and save it.
Open the command line as an administrator
①Restart mysql:
1、net stop mysql 2、net start mysql
②Enter mysql, log in to
mysql -u root -p
without entering a password, just press Enter (if Enter Password appears, press Enter directly, and you can log in successfully)
③Enter use mysql to modify root password:
update user set authentication_string=password('new password') where user='root';
flush privileges;
④ Exit:
quit;
⑤ Restart mysql again:
1、net stop mysql 2、net start mysql
⑥Whether the test is successful is whether the login is successful.
mysql -u root -p
Enter Password > 'New Password'
There will be no mistakes, you can log in! ! !
(Another situation is that you entered the wrong password. If this is the first time you log in after initialization, if this happens, there is a high probability that the password is wrong. Check the password after initialization carefully, it may be because of spaces, decimal points etc. symbol input error)