1.停止mysql 服务
systemctl stop mysqld.service
2.修改/etc/my.cnf ,增加 skip-grant-tables
[mysqld] skip-grant-tables
3.启动mysql
systemctl start mysqld.service mysql -u root -p
4.修改密码
use mysql ALTER USER 'root'@'localhost' IDENTIFIED BY '123'
5.去掉skip-grant-tables配置,重启mysql
6.修改远程配置
update user set host = '%' where user = 'root'; ALTER USER 'root'@'%' IDENTIFIED BY '123456' PASSWORD EXPIRE NEVER;