MYSQL8.0以上版本密码忘记修改教程

mysql 8.0 忘记登录密码怎么办

将近两个月没有碰MYSQL 了,刚刚捡起来,结果发现登录密码忘记了,试了N次,没办法求助网络,但是单凭一篇教程还真是解决不了问题,最后综合若干个教程才重新设置了我的密码。
MySQL 版本 8.0.28

一、无密码进入MySQL

忘记了密码,只能通过越过登录进入 MySQL 。

A. 以管理员方式运行CMD

B.关闭MySQL服务

语句:net stop mysql

C:\Windows\system32>net stop mysql
MySQL 服务正在停止.
MySQL 服务已成功停止。

C.更改无密码进入方式

语句:mysqld --console --skip-grant-tables --shared-memory

C:\Windows\system32>mysqld --console --skip-grant-tables --shared-memory

2022-08-16T12:46:38.901983Z 0 [Warning] [MY-010915] [Server] 'NO_ZERO_DATE', 'NO
_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with st
rict mode. They will be merged with strict mode in a future release.
2022-08-16T12:46:38.901986Z 0 [System] [MY-010116] [Server] C:\Program Files\mys
ql-8.0.28-winx64\bin\mysqld.exe (mysqld 8.0.28) starting as process 4292
2022-08-16T12:46:38.964384Z 1 [System] [MY-013576] [InnoDB] InnoDB initializatio
n has started.
2022-08-16T12:46:39.291986Z 1 [System] [MY-013577] [InnoDB] InnoDB initializatio
n has ended.
2022-08-16T12:46:39.447985Z 0 [Warning] [MY-011311] [Server] Plugin mysqlx repor
ted: 'All I/O interfaces are disabled, X Protocol won't be accessible'
2022-08-16T12:46:39.557187Z 0 [Warning] [MY-010068] [Server] CA certificate ca.p
em is self signed.
2022-08-16T12:46:39.572784Z 0 [System] [MY-013602] [Server] Channel mysql_main c
onfigured to support TLS. Encrypted connections are now supported for this chann
el.
2022-08-16T12:46:39.619588Z 0 [System] [MY-010931] [Server] C:\Program Files\mys
ql-8.0.28-winx64\bin\mysqld.exe: ready for connections. Version: '8.0.28'  socke
t: ''  port: 0  MySQL Community Server - GPL.

D. 以普通身份打开另一个CMD窗口

E. 进入MySQL

语句:mysql

C:\Users\zkz>mysql
mysql>

至此,我们就实现了无密码进入MySQL

二、修改密码

A. 清空密码

语句:update user set authentication_string=‘’ where user=‘root’;

mysql> update user set authentication_string='' where user='root';
Query OK, 1 row affected (0.10 sec)
Rows matched: 1  Changed: 1  Warnings: 0

B. 刷新

语句:flush privileges;

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

C. 更改密码

语句:ALTER USER ‘root’@‘localhost’ IDENTIFIED WITH mysql_native_password BY ‘新密码’

mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH 
mysql_native_password BY '123';
Query OK, 0 rows affected (0.02 sec)

三、用新的密码进入MySQL

A. 以管理员身份进入CMD

B. 启动MySQL服务

语句:net start mysql

C:\Windows\system32>net start mysql
MySQL 服务正在启动 .
MySQL 服务已经启动成功。

C. 用新密码登录

C:\Windows\system32>mysql -u root -p
Enter password: ***
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.28 MySQL Community Server - GPL

Copyright (c) 2000, 2022, 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>

成功!!!!

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值