在mysql 5.7.9以后废弃了password字段和password()函数;authentication_string:字段表示用户密码。
步骤1.查询当前root用户authentication_string字段下是否有内容,如果有内容先将其改为空,没有内容就进行步骤2。
查询语句:
use mysql;
update user set authentication_string='' where user='root'
步骤2.使用alter修改root用户密码,方法为 alter user'root'@'localhost'IDENTIFIED BY '新密码'。如下:
alter user 'root'@'localhost' IDENTIFIED BY 'newpassword'
1、不需要flush privileges来刷新权限。
2、密码要包含大写字母,小写字母,数字,特殊符号。
修改成功; 重新使用用户名密码登录即可;
注意: 一定不要采取如下形式该密码:
use mysql;
update user set authentication_string="newpassword" where user="root";
这样会给user表中root用户的authentication_string字段下设置了newpassword值;
当再使用ALTER USER 'root'@'localhost' IDENTIFITED BY 'newpassword' 时会报错的;
因为authentication_string字段下只能是mysql加密后的41位字符串密码;其他的会报格式错误;
如果连接navicat连接mysql报1521
在MySQL 8.04前,执行:SET PASSWORD=PASSWORD('[新密码]');但是MySQL8.0.4开始,这样默认是不行的。因为之前,MySQL的密码认证插件是“mysql_native_password”,而现在使用的是“caching_sha2_password”。
so,我们这里需要再次修改一次root密码。
先登录进入mysql环境:执行下面三个命令。(记得带上分号)
use mysql;
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '新密码';
FLUSH PRIVILEGES;
转载请说明出处:第六感博客 原文链接: