mysql 更新完密码,总是拒绝连接、登录失败?
MySQL8.0 不能通过直接修改 mysql.user 表来更改密码。
因为authentication_string字段下只能是MySQL加密后的43位字符串密码,其他的导致错误。错误不报出,但是无法再登录mysql,总是会提示 无法认证。
参考:MySQL8.0
mysql> USE mysql;
Database changed
mysql> UPDATE user SET authentication_string="123456" WHERE user="root";
Query OK, 1 row affected (0.39 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> FLUSH privileges; # 刷新保存
Query OK, 0 rows affected (0.13 sec)
# mysql 5.7.9 之后取消了`password` 函数,`authentication_string=password("123456")` 会报错
C:\WINDOWS\system32>mysql -u root -p
Enter password: ******
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
如果 你已经这样更改密码,并且导致了无法进入mysql。本人表示同情之时,还为了你提供了详细的解决方案。请查看本文备注:清空root 密码
正确更改密码的方式
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY "your_password";
mysql> USE mysql;
Database changed
mysql> ALTER USER 'root'@'localhost' IDENTIFIEED WITH mysql_native_password BY "markjun";
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL ser