当前位置:网站首页>MySQL中忘记用户密码怎么办?
MySQL中忘记用户密码怎么办?
2022-08-11 05:32:00 【欢喜躲在眉梢里】
在登录MySQL的时候,如果忘记密码了应该怎么办?对于不同的用户有不同的密码破解方式。
目录
一、其他的普通用户
使用超级用户登录,直接去修改密码就可以了。
alter user 'cali'@'%' identified by 'xxxx';
其中的xxxx是修改为你想改的密码。本质上是修改mysql库里的user表里的对应的用户的auth_string。
二、超级用户
[email protected] :只能在本地登录。
①修改/etc/my.cnf :加入skip-grant-tables表示跳过密码验证。
②使用另外一个管理员账号
③修改停止mysqld服务---中断业务
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 #需要禁用密码复杂性策略第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.在进入数据库中执行设置密码的命令:alter user 'root'@'localhost' identified by 'xxxx';这条命令时会报错。
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所以需要先刷新权限在执行上面那条设置密码的命令。
flush privileges; 会加载原来没有加载的权限表(重新加载跳过的表)--》用户名和密码所在的表user等)
mysql> flush privileges; 刷新权限(会加载原来没有加载的权限表(重新加载跳过的表)--》用户名和密码所在的表user等)
Query OK, 0 rows affected (0.01 sec)设置密码:两种方法(任选其一):xxxx是表示你要设置的新密码。
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> : mysql里完整的用户信息是 用户名@主机名。
第5步:重新修改mysql的配置文件
vim /etc/my.cnf
[mysqld]
socket=/data/mysql/mysql.sock
#user=mysql --》注释掉
#skip-grant-tables --》注释掉记得将刚刚添加的注释掉,不能如果跳过密码验证的话,你是MySQL是不安全的哦。
第6步:刷新服务
service mysqld restart
[[email protected] mysql]# service mysqld restart #重新刷新服务
Shutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS! 第7步:验证修改密码是否成功
使用你刚刚修改之后的密码重新登录数据库看密码是否修改成功。
[[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';
以上就是忘记MySQL用户密码,修改密码的整个过程,希望你能记得住密码, 用不到这篇文章。
边栏推荐
猜你喜欢
随机推荐
C语言-6月8日-给定一个字符数组‘i am a student’ 统计字符a的个数并进行输出
swagger常用注释API @ApiModel、@ApiModelProperty的用法
无胁科技-TVD每日漏洞情报-2022-7-21
heap2 (tcache attack,house of orange)
第六届蓝帽杯 EscapeShellcode
Gradle 相关知识总结
5月leetcode-C#刷题日志(持续更新中)
Lua 协同程序(coroutine)
Unity 数字跳字功能
【LeetCode-414】第三大的数
[HTB]渗透Backdoor靶机
poco源码简单分析
BaseFragment的抽取
手把手导入企业项目(快速完成本地项目配置)
Redis学习笔记【二】
Msfvenom生成后门及运用
C# 基础之字典——Dictionary(二)
nepctf Nyan Cat 彩虹猫
web网络安全笔记
Content Size Fitter的使用









