centos7 mysql5.7 忘记密码

  1. 编辑mysql配置文件
    
    vim /etc/my.cnf
    
    在其中添加skip-grant-tables 保存

     

  2. 重启mysql服务
    #  systemctl restart mysqld

     

  3. 使用无密码命令登录mysql数据库
    #mysql

     

  4. 使用下面语句修改root密码
    mysql> update mysql.user set authentication_string=password('新密码') where user='root';
    Query OK, 1 row affected, 1 warning (0.00 sec)
    Rows matched: 1  Changed: 1  Warnings: 1
    
    mysql> flush privileges;
    Query OK, 0 rows affected (0.01 sec)
    
    mysql>quit

     

  5. 编辑mysql配置文件,将之前添加的skip-grant-tables去掉

     

  6. 重启mysql服务   #  systemctl restart mysqld

     

  7. #登录mysql
    mysql -u用户名 -p
    #输入密码

     

posted @ 2020-06-24 09:40  手可摘星辰/*  阅读(266)  评论(0编辑  收藏  举报