mysql 8 修改root密码

版权声明:本文为博主原创文章,用来记录学习过程,欢迎交流学习。 https://blog.csdn.net/k_young1997/article/details/88628207

之前用的是MySQL 5.7 的版本,因为在user表中没有password字段,一直使用下边的方式来修改root密码

use mysql; 
update user set authentication_string = password(“root”) where user = “root”;

最近因为要写一个小项目要用MySQL8.0.11版本,装好MySQL后用上边方法修改密码,一直报错。后来去掉password()函数后,没有报错,但是输入密码时不对。

查阅后才知道在mysql 5.7.9以后废弃了password字段和password()函数;authentication_string:字段表示用户密码,而authentication_string字段下只能是mysql加密后的41位字符串密码。
所以需要用一下方式来修改root密码:

ALTER user 'root'@'localhost' IDENTIFIED BY 'newpassword';

此方法不需要flush privileges来刷新权限。

猜你喜欢

转载自blog.csdn.net/k_young1997/article/details/88628207