5.7之前修改密码语句
update user set authentication_string = password(“root”) where user = “root”;
mysql 5.7.9以后废弃了password字段和password()函数;并在user表加了authentication_string:字段表示用户密码
#进入到mysql 安装目录下
 #停止 mysql 服务
service mysqld stop 
修改配置文件开启安全模式
  
 vim /etc/my.cnf 
添加一下命令后,保存退出
skip-grant-tables 

重启mysql
systemctl restart mysqld 
启动mysql然后进入命令行模式,已经是安全模式了
#输入命令后回车,即可登录
mysql -u root -p 
选择数据库
use mysql;  
将authentication_string设置为空串,刷新并退出数据库
update user set authentication_string='' where user='root';
flush privileges; 
将配置文件my.cnf中的skip-grant-tables注释掉
vim /etc/my.cnf 

重启mysql
systemctl restart mysqld 
进入安全模式,输入命令后回车登录
mysql -u root -p 
,选择数据库
use mysql; 
查询root用户对应的host
select user,host from user; 

执行修改密码语句 ,并刷新
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123';
flush privileges;
 
如果提示密码等级不符合规范,在 /etc/my.cnf 中添加一下代码
validate_password.policy=0 
 
退出mysql,重启服务
 service mysqld restart 
重新使用密码登录即可






![【洛谷/水滴题解】[NOIP2005 普及组] 采药](https://i-blog.csdnimg.cn/direct/04d90d9b60eb4503b946f925911d1bd9.png)





![基于RK3568 Android11 移除长按电源按键弹窗的对话框中的 [关机] 和 [紧急呼救] 选项(详细分析)](https://i-blog.csdnimg.cn/direct/d40420653a5a41faae53c4535effdc95.png#pic_center)





