zoukankan      html  css  js  c++  java
  • 【MySQL解惑笔记】忘记MySQL数据库密码

    破解MySQL密码

    一、MySQL5.7.5之前

    只要有系统root密码就可以破解:
    [root@host-131 ~]# vim /etc/my.cnf               //在配置文件中加入如下内容
    [mysqld]
    skip-grant-tables
    
    [root@host-131 ~]# systemctl restart mysqld           //重启MySQL服务
    [root@host-131 ~]# mysql
    mysql> update mysql.user set password=password("Yanglt456.") where user="root" and host="localhost";    //设置密码
    mysql> flush privileges;                     //刷新                          
    mysql> q
    
    [root@host-131 ~]# vim /etc/my.cnf                          //注释掉下边内容,或者直接删除
    [mysqld]
    #skip-grant-table
    [root@host-131 ~]#systemctl restart mysqld           //重启服务

    一、MySQL5.7.6之后

    [root@host-131 ~]# vim /etc/my.cnf
    [mysqld]
    skip-grant-tables
    mysql> select user,host,authentication_string from mysql.user;
    +---------------+-----------+-------------------------------------------+
    | user          | host      | authentication_string                     |
    +---------------+-----------+-------------------------------------------+
    | root          | localhost | *8F59EEA84BC6AA6A57ECD4C0377518281DADC1BA |
    | mysql.session | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
    | mysql.sys     | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
    +---------------+-----------+-------------------------------------------+
    3 rows in set (0.01 sec)
    
    mysql> desc mysql.user;
    +------------------------+-----------------------------------+------+-----+-----------------------+-------+
    | Field                  | Type                              | Null | Key | Default               | Extra |
    +------------------------+-----------------------------------+------+-----+-----------------------+-------+
    | Host                   | char(60)                          | NO   | PRI |                       |       |
    | User                   | char(32)                          | NO   | PRI |                       |       |
    | authentication_string  | text                              | YES  |     | NULL                  |       |
    | password_expired       | enum('N','Y')                     | NO   |     | N                     |       |
    | password_last_changed  | timestamp                         | YES  |     | NULL                  |       |
    | password_lifetime      | smallint(5) unsigned              | YES  |     | NULL                  |       |
    | account_locked         | enum('N','Y')                     | NO   |     | N                     |       |
    +------------------------+-----------------------------------+------+-----+-----------------------+-------+
    45 rows in set (0.01 sec)
    
    mysql> update mysql.user set authentication_string=password("Yanglt456.") where user="root";
    mysql> flush privileges;
    mysql> q
    
    [root@host-131 ~]# vim /etc/my.cnf
    [mysqld]
    #skip-grant-tables  //注释掉
    [root@host-131 ~]# systemctl restart mysqld            //重启mysql服务
    [root@host-131 ~]# mysql -p"Yanglt456."                //密码已改变
  • 相关阅读:
    Linux 下建立 Git 与 GitHub 的连接
    PHP Redis 对象方法手册
    wampServer 安装 Redis 扩展
    CentOS 与 Ubuntu 使用命令搭建 LAMP 环境
    Xshell 连接 CentOS 7 与 Ubuntu Server
    使用那各VUE的打印功能(print.js)出现多打印一个空白页的问题
    MySql数据库,查询数据导出时会出现重复的记录(数据越多越明显)
    解决 nginx 启动错误 nginx: [emerg] host not found in upstream
    关于nginx配置的一个报错connect() to unix:/tmp/php-cgi.sock failed (2: No such file or directory)
    网站的ssl证书即将过期,需要续费证书并更新
  • 原文地址:https://www.cnblogs.com/yangleitao/p/9109607.html
Copyright © 2011-2022 走看看