Mysql密码忘记后怎么重置密码,mysql8之后有改动
创始人
2024-02-29 23:45:54
0

mysql8之前的修改方式:

1.管理员身份打开cmd:然后关闭mysql,停止MySQL服务,输入 net stop mysql 停止服务

2.切换到MySQL的bin文件下,输入mysqld --console --skip-grant-tables --shared-memory。

 

3上个窗口保留不要关闭,保证MySQL可以免密码登录,
新开管理员命令行,切换到MySQL的bin文件下,
输入mysql -uroot -p回车,不用输入密码,直接按回车跳过,
输入use mysql,进入数据库成功,
输入update user set password=PASSWORD('123456') where USER='root';
更新数据库成功。

mysql8版本之后修改方式:

mysql8之前用上面的方式修改会报语法错误:

mysql>  UPDATE user SET password=PASSWORD(123456) WHERE user='root';
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(123456) WHERE user='root'' at line 1

 查看mysql user 表发现表中没有password 字段,所以update user set password 会出错,查找资料发现mysql 8.0.2之后数据库,密码规则发生变化,改变了user表。

正确更新root 密码的方法。

1.打开cmd 启动 mysql 跳过 权限验证

mysqld --skip-grant-tables --shared-memory --console

2.打开cmd

C:\Users\gongcm>mysql
mysql>
mysql> flush privileges;
Query OK, 0 rows affected (1.86 sec)
mysql> alter user 'root'@'localhost' IDENTIFIED BY '123456'; # 123456 为你要修改的密码
Query OK, 0 rows affected (0.42 sec)
mysql> exit;


3.关闭 mysqld 启动 cmd 窗口
重新打开cmd,输入命令
# 启动 mysql 

net start mysql


#登录

C:\Users\gongcm>mysql -u root -p
Enter password: ******
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.18 MySQL Community Server - GPLCopyright (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.mysql>

相关内容

热门资讯

监控摄像头接入GB28181平... 流程简介将监控摄像头的视频在网站和APP中直播,要解决的几个问题是:1&...
Windows10添加群晖磁盘... 在使用群晖NAS时,我们需要通过本地映射的方式把NAS映射成本地的一块磁盘使用。 通过...
protocol buffer... 目录 目录 什么是protocol buffer 1.protobuf 1.1安装  1.2使用...
Fluent中创建监测点 1 概述某些仿真问题,需要创建监测点,用于获取空间定点的数据࿰...
educoder数据结构与算法...                                                   ...
MySQL下载和安装(Wind... 前言:刚换了一台电脑,里面所有东西都需要重新配置,习惯了所...
MFC文件操作  MFC提供了一个文件操作的基类CFile,这个类提供了一个没有缓存的二进制格式的磁盘...
在Word、WPS中插入AxM... 引言 我最近需要写一些文章,在排版时发现AxMath插入的公式竟然会导致行间距异常&#...
有效的括号 一、题目 给定一个只包括 '(',')','{','}'...
【Ctfer训练计划】——(三... 作者名:Demo不是emo  主页面链接:主页传送门 创作初心ÿ...