-
首先,修改/etc/my.cnf文件
在[mysqld]中添加skip-grant-tables
重启mysqlsystemctl restart mysql
-
进入mysql
mysql -uroot
此步就无需输入密码了 -
修改密码
update user set authentication_string=password('新密码') where user="root";
这里 修改密码使用的字段 authentication_string,这个是新版本的用法,
旧版本使用的是password,相应的修改密码语句如下
update user set password=password('新密码') where user="root";
4. 使更改生效 : flush privileges
5. 退出MySQL
6. 修改/etc/my.cnf,将开始添加的skip-grant-tables
去除
7. 重启mysql
8. 使用新密码登录mysql,成功登录