mysql(root)密码破解重置-mysql密码忘记怎么办?

mysql破解密码

1.设置mysql免密登陆

# vim /etc/my.cnf.d/mysql-server.cnf  #主配置文件[mysqld]下面添加以下内容
[mysqld]
skip-grant-tables  #免密的登陆
#重启mysql
# systemctl restart mysqld

2.查看数据库中用户的密码,此时是加密状态

mysql> select host,user, authentication_string from mysql.user;
+-----------+------------------+------------------------------------------------------------------------+
| host      | user             | authentication_string                                                  |
+-----------+------------------+------------------------------------------------------------------------+
| localhost | mysql.infoschema | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| localhost | mysql.session    | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| localhost | mysql.sys        | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| localhost | root             | *23AE809DDACAF96AF0FD78ED04B6A265E05AA257                              |
+-----------+------------------+------------------------------------------------------------------------+
4 rows in set (0.00 sec)

2.把mysql库下user表中 用户root的密码设置为无;

# mysql  #进入mysql
mysql> update mysql.user set authentication_string="" where user="root";

+-----------+------------------+------------------------------------------------------------------------+
| host | user | authentication_string |
+-----------+------------------+------------------------------------------------------------------------+
| localhost | mysql.infoschema | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| localhost | mysql.session | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| localhost | mysql.sys | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| localhost | root | |
+-----------+------------------+------------------------------------------------------------------------+
4 rows in set (0.00 sec)

4.设置mysql中root用户的密码

mysql>alter user root@"localhost" identified by "123";   #密码设置为123
mysql> flush privileges; #使命令生效
mysql> exit;
Bye

5.解除免密登陆

# vim /etc/my.cnf.d/mysql-server.cnf  #主配置文件添加以下内容
[mysqld]
#skip-grant-tables  #注释掉免密的登陆
#重启mysql
# systemctl restart mysqld  
# mysql -uroot -p123 #使用刚重新设置的密码登陆mysql

 

 

知识扩展:

初始化设置mysql root用户密码

root@mysql20 ~]# mysqladmin  -uroot -p  password "123"
Enter password: //敲回车
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
 [root@mysql20 ~]# mysql //无密码连接被拒绝
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@mysql20 ~]#
[root@mysql20 ~]# mysql -uroot –ptarena  //连接时输入密码

 

posted @ 2023-08-07 14:29  小小一兆  阅读(132)  评论(0编辑  收藏  举报