zoukankan      html  css  js  c++  java
  • MySQL破解root用户密码

    1.先停掉mysql服务
    
    # service mysqld stop
    
    2.跳过授权表启动mysql服务
    
    # mysqld_safe --skip-grant-tables &
    
    3.更新root密码
    
    mysql> update mysql.user set password=password('sunxianjiu123') where user='root' and host='localhost';
    mysql> flush privileges;
    4.退出数据库,杀死mysql跳过授权登陆方式服务
    
    # ps -ef |grep mysql
    
    • 环境:CentOS 7
    • MySQL版本:MySQL 5.7.29

    一、停止MySQL进程的运行

    service mysqld stop
    

    二、修改配置文件

    vim /etc/my.cnf
    

    在[mysqld]下添加两行:

    user=mysql
    skip-grant-tables
    

    第一行user=mysql的意思是指定启动MySQL进程的用户。第二行是关键,skip-grant-tables的意思是跳过密码验证。
    wq保存退出。

    三、启动MySQL进程

    service mysqld start
    

    四、直接登录MySQL,不接密码

    img

    五、修改密码

    要注意的是,此时直接修改密码会报错,如下所示。

    错误语句:ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
    看不懂英文就扔谷歌翻译:
    img

    解决办法是刷新权限,加载原来没有加载的权限表。

    msyql> flush privileges;
    skip-grant-tables语句就是绕过了grant授权表,实现免密登录,而执行flush privileges之后就相当于加载了grant授权表。

    另外修改密码不能直接使用set password='Charramma';命令修改。
    img

    报错说没有在用户表中找到匹配的行。
    正确的语法应该是下面这样:

    msyql> set password for 'root'@'localhost' = 'Charramma123#';
    如下,修改成功。
    img

    六、修改MySQL配置文件

    就是把之前添加的两行内容注释掉或删除掉。

    七、重启MySQL服务

    service mysqld restart

    八、使用新密码登录

    img
    参考:https://www.cnblogs.com/CharrammaBlog/p/12993735.html?ivk_sa=1024320u
    https://blog.csdn.net/qq_17805763/article/details/89518656

    1.内容有错还请在评论区指出哦!谢谢!
  • 相关阅读:
    js保留几位小数
    IE的卸载之路(折腾1个多月,记录下。。)
    百度map
    鼠标滑轮事件监听,兼容各类浏览器
    sql server分页存储过程
    echarts(3.0)的基本使用(标签式导入)
    datagrid加分组后的效果
    python文件操作
    python求100以内素数
    python 三元运算符
  • 原文地址:https://www.cnblogs.com/bbdbolg/p/15032940.html
Copyright © 2011-2022 走看看