当前位置:网站首页>What should I do if I forget the user password in MySQL?

What should I do if I forget the user password in MySQL?

2022-08-11 06:56:00 happy hiding in the eyebrows

在登录MySQL的时候,What to do if you forget your password?There are different password cracking methods for different users.

目录

一、其他的普通用户

二、超级用户

1、破解MySQL的密码

2、 另外一种方式(Windows软件中修改)


一、其他的普通用户

使用超级用户登录,Just change the password directly.

alter user 'cali'@'%' identified by 'xxxx';  

其中的xxxxIt is changed to the password you want to change.本质上是修改mysql库里的user表里的对应的用户的auth_string.

二、超级用户

[email protected] :只能在本地登录.

①修改/etc/my.cnf :加入skip-grant-tables表示跳过密码验证.

②Use another administrator account

③Modify stopmysqld服务---中断业务

1、破解MySQL的密码

第1步:停止MySQL进程的运行.

service mysqld stop

[[email protected] mysql]# service mysqld stop
Shutting down MySQL.. SUCCESS! 

第2步:修改配置文件.

vim /etc/my.cnf在其中加入一行:skip-grant-tables表示跳过密码验证

[email protected] mysql]# vim /etc/my.cnf
[mysqld]
user=mysql     #指定启动MySQL进程的用户
skip-grant-tables  #跳过密码验证(加入这一行)
#validate-password=off  #Password complexity policy needs to be disabled

 第3步:启动MySQL进程.

service mysqld start

[[email protected] mysql]# service mysqld start  启动MySQL进程
Starting MySQL. SUCCESS! 

 第4步:登录MySQL,不接密码.

mysql -uroot -p

[[email protected] mysql]# mysql  -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.25 Source distribution

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

 Execute the command to set the password in the database:alter user 'root'@'localhost' identified by 'xxxx';This command will give an error.

mysql> alter user 'root'@'localhost' identified by  'xxxx'; --》会报错
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement

So you need to refresh the permissions first before executing the above command to set the password.

flush privileges; 会加载原来没有加载的权限表(Reload skipped tables)--》用户名和密码所在的表user等)

mysql> flush privileges; 刷新权限(会加载原来没有加载的权限表(Reload skipped tables)--》用户名和密码所在的表user等)
Query OK, 0 rows affected (0.01 sec)

设置密码:两种方法(任选其一):xxxxis the new password you want to set.

set password for 'root'@'localhost' = 'xxxxx';

alter user 'root'@'localhost' identified by 'xxxx';

mysql> set password for 'root'@'localhost' = 'xxxxx';    --》修改密码,指定用户名为[email protected]
Query OK, 0 rows affected (0.00 sec)

[email protected](none) 10:35  scmysql>alter user  'root'@'localhost'  identified by 'xxxx';
Query OK, 0 rows affected (0.00 sec)

#退出MySQL
mysql> quit
Bye

 扩展:[email protected](none) 10:40 scmysql>    : mysqlThe complete user information here is 用户名@主机名.

第5步:重新修改mysql的配置文件

vim /etc/my.cnf

[mysqld]
socket=/data/mysql/mysql.sock
#user=mysql    --》注释掉
#skip-grant-tables           --》注释掉

Remember to comment out the one you just added,Not if password verification is skipped,你是MySQLOh it's not safe.

第6步:刷新服务

 service mysqld restart

[[email protected] mysql]# service mysqld restart  #Refresh the service
Shutting down MySQL.. SUCCESS! 
Starting MySQL. SUCCESS! 

 第7步:Verify that the password change is successful

Use the password you just changed to log in to the database again to see if the password is changed successfully.

[[email protected] mysql]# mysql  -uroot -p'xxxxx'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.25 Source distribution

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

2、 另外一种方式(Windows软件中修改)

就是使用其他的管理员账号给别的用户重新设置密码.可以在SQLyog里操作.

SET PASSWORD FOR 'root'@'localhost' = 'xxxxx';

alter user 'root'@'localhost' identified by 'xxxxx';

The above is to forgetMySQL用户密码,The entire process of changing the password,Hope you can remember the password, Can't use this article.

原网站

版权声明
本文为[happy hiding in the eyebrows]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/223/202208110516510611.html