首页 > 【MySQL解惑笔记】忘记MySQL数据库密码

【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."                //密码已改变

 

转载于:https://www.cnblogs.com/yangleitao/p/9109607.html

更多相关:

  • 一.通过Keepalived搭建MySQL双主模式的高可用集群系统1.MySQL Replication介绍:MySQL Replication是MySQL自身提供的一个主从复制功能,其实也就是一台MySQL服务器(称为Slave)从另一台MySQL服务器(称为Master)上复制日志,然后解析日志并应用到自身的过程。MySQL Re...

  • 1、打开https://oneinstack.com/auto/选择Stack:LNMTY → ×安装Nginx → √安装JAVA:Tomcat7.0、JDK1.7 → √安装数据库MySQL5.7、DB密码root、DB安装方式二进制安装 → √Pure-FTPd √redis √memcached ×hhvm √iptables...

  • 注意:由于流程太过于繁杂,且坑多,这里只保留关键步骤,具体小问题百度! ________________________ 先进入CentOS6.8图形化界面(如阿里云没有默认的图形化界面,自己去安装https://blog.csdn.net/fenglixiong123/article/details/71138017) 【步骤...

  • 为了简单省事,我在CentOS 6.3上直接使用yum方法来安装MySQL,安装很顺利,但是我发现root用户登录不了。 下面是参考网上的资料并实操后的笔记整理 yum -y install mysql-server service mysqld start 安装过程中没有任何提示,也不知道root的密码设置的是多少。我打算从...