Mysql account username is correct but cannot log in problem solved

My local mysql version is 5.7.19, and the user name and password I set are root/root. It was working fine a few days ago, but suddenly one day I cannot log in after entering the correct user name and password, and the error is as follows:

 

XUEXUEdeMacBook-Pro:MyShells xuexue$ mysql -uroot -proot
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

 Many people say that the password is changed directly by skipping the authentication. I also tried it. The steps are to find the bin under the mysql installation path and run

./mysqld_safe  --skip-grant-tables &

 Then you can log in directly without password, look up the user table, and change the password to 123456 in the following way

update user set authentication_string='123456' where user='root';

 It doesn't work, you will find that the password style in this column is very unsocial, it should not be plaintext, it should be encrypted, look at the result

mysql> select user,host,authentication_string from user;

+---------------+-----------+-------------------------------------------+

| user          | host      | authentication_string                     |

+---------------+-----------+-------------------------------------------+

| root          | localhost | 123456                                    |

| mysql.session | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |

| mysql.sys     | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |

+---------------+-----------+-------------------------------------------+

 

3 rows in set (0.00 sec)

 

And by looking at the user table, it is found that the password_expired of the root user is Y, which means that it has expired. This is not something that can be changed by the above update statement.

The final solution to this problem is to pass

GRANT ALL PRIVILEGES ON *.* TO root@localhost IDENTIFIED BY '123456';

 After executing, execute

flush privileges;

 Then you can log in successfully through mysql -uroot -p123456

 

If you think the article is good, please encourage it :D

 

 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326110536&siteId=291194637