Linux下Mysql5.7忘记密码

一、问题

linux下的mysql5.7忘记密码

二、解决

  • 第一步:打开mysql5.7的配置文件my.cnf,并在里面增加一行:skip-grant-tables   保存并退出(:wq)
[root@iz09a32x1sghz3z ~]# vi /etc/my.cnf

image

  • 第二步:重启mysql
[root@iz09a32x1sghz3z ~]# service mysqld restart
  • 第三步:登录mysql并且修改密码

用root账号登录: [root@iz09a32x1sghz3z ~]# mysql -u root

使用mysql中的mysql数据库: mysql> use mysql;

修改密码:  update user set authentication_string = password("Szfore_68638") where user="root" ;

刷新数据库: flush privileges;

退出: quit;

注意:mysql5.7的user表中的password字段已经改成了authentication_string 字段了。

这时候,需要输入的命令是update user set authentication_string = password("Szfore_68638") where user="root" ;

  • 第四步:打开mysql5.7的配置文件my.cnf,把刚增加这行:skip-grant-tables  删除掉 保存并退出(:wq)
  • 第五步:重新启动mysql,即可用修改好的密码登录了。
[root@iz09a32x1sghz3z ~]# service mysqld restart
posted @ 2019-05-10 16:23  青阳闲云  阅读(6638)  评论(1编辑  收藏  举报