mysql密码忘了怎么办

mysql8.0以下版本密码忘了怎么办

思路:mysql的密码是存放在user表里面的,修改密码其实就是修改表中记录,重置的思路是是想办法不用密码进入系统,然后用数据库命令修改表user中的密码记录

mysql密码忘了需要采取的措施分为mysql8及以上版本和mysql8以下版本,两种不同的方法,下面将分别介绍两种方法

mysql8以下版本

0.以管理员身份打开cmd

1.输入net stop mysql       [关闭mysql服务]

2.输入mysqld --skip-grant-tables    [使用无验证方式启动mysql服务]

3.用管理员身份新打开一个新的cmd窗口,输入mysql后回车,然后就登录进去了

4.输入use mysql;     [使用mysql数据库]

5.输入update user set password=password('新密码') where user ='用户名';       [修改密码]

6.关闭两个cmd窗口

7.打开任务管理器手动结束mysql.exe进程

8.用管理员身份打开一个cmd窗口输入net start mysql     [开启mysql服务]

9.使用新密码登录

windows下mysql8密码忘了怎么办

0.以管理员身份打开cmd

1.输入net stop mysql       [关闭mysql服务]

2.输入mysqld --console  --skip-grant-tables --shared-memory     [使用无验证方式启动mysql服务]

3.打开一个新的cmd窗口,输入mysql -u用户名 -p回车

4.提示输入密码时直接回车跳过      [回车后就已经进入mysql了]

5.输入use mysql;     wgetmysql数据库]

6.输入update user set authentication_string='' where user='用户名';       [更改密码]

7.输入exit    [退出mysql数据库]

8.关掉所有cmd窗口

9.输入net start mysql        [重新开启mysql服务]

10.输入mysql -u用户名 -p回车

11.提示输入密码时直接回车跳过      [回车后就已经进入mysql了]

12.输入alter user '用户名'@'localhost' identified with mysql_native_password by '新密码';     [更改新的密码]

13.输入flush privileges;   [刷新一下]

14.退出mysql后就可以用新密码登录了

CentOS8下mysql8密码忘了怎么办

1.切换到root身份,输入su -回车,然后输入root密码

2.找到mysql的配置文件my.cnf,用vim打开,如果是通过yum安装的,配置文件的路径为/etc/my.cnf

3,进入配置文件my.cnf,在[mysqld]下添加skip-grant-tables,然后保存退出

[mysqld]
server_id=2
relay-log=relay-log
relay-log-index=relay-log.index
skip-grant-tables             #在[mysqld]下添加此行。
port = 3306

4.重启mysql,输入下面命令,先关闭后启动

systemctl stop mysql
systemctl start  mysql

5,此时可以不用密码直接进入mysql,输入mysql -uroot -p,后回车,提示输入密码时回车,此时就进入了

[root@VM-4-6-centos ~]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.24 Source distribution

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

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.

mysql> 

6.重新设置密码,这三条命令缺一不可

flush privileges;    #刷新mysql
alter user "root"@"localhost" identified by "重新设置的密码";   #设置新的密码
flush privileges;    #刷新mysql

mysql> flush privileges; 
Query OK, 0 rows affected (0.10 sec)

mysql> alter user "root"@"localhost" identified by "重新设置的密码";
Query OK, 0 rows affected (0.11 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

7.把刚才添加到my.cnf中的那一句skip-grant-tables删除

8.重启mysql,输入下面命令,先关闭后启动

systemctl stop mysql
systemctl start  mysql

有趣的小知识

大家都知道MySQL的用户信息是存储在mysql数据库下的user表中的,打开user表是可以直接看到所有用户名和所对应的权限的,

当然密码也可以看到(看到的密码是经过md5加密后的),机智的程序员会想到用md5解密所看到的密码

下面推荐一个网站: https://www.cmd5.com/

把密文输入到输入到密文框中查询即可

例:

是不是很有趣(´▽`)ノ 

结束

  • 5
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值