破解MySQL密码
一、MySQL5.7.5之前
只要有系统root密码就可以破解:
[root@host- ~]# vim /etc/my.cnf //在配置文件中加入如下内容
[mysqld]
skip-grant-tables [root@host- ~]# systemctl restart mysqld //重启MySQL服务
[root@host- ~]# mysql
mysql> update mysql.user set password=password("Yanglt456.") where user="root" and host="localhost"; //设置密码
mysql> flush privileges; //刷新
mysql> \q [root@host- ~]# vim /etc/my.cnf //注释掉下边内容,或者直接删除
[mysqld]
#skip-grant-table
[root@host- ~]#systemctl restart mysqld //重启服务
一、MySQL5.7.6之后
[root@host- ~]# 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 |
+---------------+-----------+-------------------------------------------+
rows in set (0.01 sec) mysql> desc mysql.user;
+------------------------+-----------------------------------+------+-----+-----------------------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------------------+-----------------------------------+------+-----+-----------------------+-------+
| Host | char() | NO | PRI | | |
| User | char() | NO | PRI | | |
| authentication_string | text | YES | | NULL | |
| password_expired | enum('N','Y') | NO | | N | |
| password_last_changed | timestamp | YES | | NULL | |
| password_lifetime | smallint() unsigned | YES | | NULL | |
| account_locked | enum('N','Y') | NO | | N | |
+------------------------+-----------------------------------+------+-----+-----------------------+-------+
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- ~]# vim /etc/my.cnf
[mysqld]
#skip-grant-tables //注释掉
[root@host- ~]# systemctl restart mysqld //重启mysql服务
[root@host- ~]# mysql -p"Yanglt456." //密码已改变