这里以Centos 7为例:
步骤:
进入mysql配置文件
vim /etc/my.cnf
在my.cnf 文件里设置跳过密码登录。
[mysqld]
skip-grant-tables
重启mysql
service mysqld restart
进入mysql ,不需要密码进入数据库
mysql 或者 mysql -u root
使用mysql 数据库
use mysql;
修改root密码
update user set password=password(‘新密码‘) where user=‘root‘;
更新权限表或重启mysql
flush privileges;
退出mysql,然后进入my.cnf 去掉skip-grant-tables。
quit ; //退出mysql
vi /etc/my.cnf //进入mysql 配置文件 ,去掉之前加的skip-grant-tables;
保存 ,重启mysql服务
service mysqld restart
root密码修改完成
原文:https://www.cnblogs.com/daxiaohaha/p/13039115.html