mysql5.7重置root密码

22次阅读

共计 523 个字符,预计需要花费 2 分钟才能阅读完成。

安装完 mysql5.7 后忘记了密码,需要重置 root 密码;
第一步:修改配置文件免密码登录 mysql
vim /etc/my.cnf
## 在 my.cnf 的 [mysqld] 字段加入
skip-grant-tables

## 重启 mysql 服务
service mysqld restart
第二步:免密码登录 mysql
mysql -u root
##password 直接回车
第三步:给 root 重置密码为空
mysql>use mysql;
## mysql 5.7.9 以后废弃了 password 字段, 字段名修改为 authentication_string
mysql>update user set authentication_string=” where user=’root’;
## 刷新数据库
mysql>flush privileges;
第四步:root 重置密码  退出 mysql,删除 /etc/my.cnf 文件最后的 skip-grant-tables 重启 mysql 服务,使用 root 用户进行登录,因为上面设置了 authentication_string 为空,所以可以免密码登录。
alter user ‘root’@’localhost’ identified by ‘# 新密码 #’;
功德圆满,修改成功

正文完
 0