当前数据库版本:
Server version: 5.7.29 MySQL Community Server (GPL)
5.7版本前修改密码可以通过
update user set password=password("xxxxx") where user="yyyy";
5.7版本后password的字段被删除了,换成了另外一个 authentication_string,所以变成了
update user set authentication_string=password("xxx") where user="yyy";
所以整个流程变成了
#1.修改my.cnf
vim /etc/my.cnf
#2.在my.cnf下添加skip-grant-tables,并保存
#3.重启服务
service mysqld restart
#4.无密码进入mysql
mysql -u root -p
#5.进入mysql数据库的user表,并修改用户密码
use mysql;
update mysql.user set authentication_string=password('Root@123') where user='root';
#6.刷新权限表
flush privileges;
#7.退出重启服务
service mysqld restart
不过8.X的版本开始又有一些变化。
ALTER USER 'test'@'localhost' IDENTIFIED WITH MYSQL_NATIVE_PASSWORD BY '新密码';”命令来修改密码即可



