锐单电子商城 , 一站式电子元器件采购平台!
  • 电话:400-990-0325

mysql 忘记密码咋办

时间:2022-08-27 11:30:00 低浓度甲烷传感器gjc4

mysql8.0压缩版

# Mysql8.0压缩版忘记密码如何重置密码(总结)

## 一、以下是Windows操作系统的操作步骤:

1. 关闭正在运行的MySQL服务-->net stop mysql

2. 打开DOS窗口,转到mysql\bin目录。

3. 输入mysqld --console --skip-grant-tables --shared-memory 回车。--skip-grant-tables 意思是启动MySQL服务时跳过权限表认证,注意skip前面是两个- ,此时DOS无法输入窗口

4. 再开一个DOS窗口,转到mysql\bin目录。

5. 输入mysql如果回车成功,就会出现MySQL提示符 >。

6. 连接权限数据库: use mysql; 。

7. 改密码:update mysql.user set authentication_string='' where user='root';

执行mysql -u root -p直接回车两次,不需要输入密码(因为前面设置了空密码)

以下信息显示修改成功;

mysql> update mysql.user set authentication_string='root' where user='root';

Query OK, 1 row affected (0.52 sec)

Rows matched: 1 Changed: 1 Warnings: 0

8. 刷新权限(必须步骤):flush privileges; 。

9. 退出mysql> quit

10. 取消系统,然后进入,使用户名root登录刚刚设置的新密码123。

## mysql8.修改新用户和密码加密规则

MySQL8.0已经发布GA目前最新版本GA版本为8.0.12.虽然与之前的版本相比,MySQL8.但是,代码重构后,0没有添加新元素,MySQL8.优化器更强大,也有一些新的特性,如支持索引隐藏。

但是,MySQL新版本也有很多不同于以前版本的地方,比如用户创建的变化。

1. 用户创建

创建用户的操作不再支持grant在创建用户的同时,需要在授权之前创建用户

mysql> grant all on *.* to 'admin'@'%' identified by 'admin123';

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 'identified by 'admin123'' at line 1

mysql> create user 'admin'@'%' identified by 'admin123';

Query OK, 0 rows affected (0.06 sec)

mysql> grant all on *.* to 'admin'@'%' ;

Query OK, 0 rows affected (0.04 sec)

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

### 2. 用户登录1

[root@gjc18 lib]# /usr/local/mysql8.0/bin/mysql -uroot -p"root!@#123" --socket=/data/mysql/mysql3310/tmp/mysql3310.sock

-bash: !@#123": event not found

[root@gjc18 lib]# /usr/local/mysql8.0/bin/mysql -uroot -p'root!@#123' --socket=/data/mysql/mysql3310/tmp/mysql3310.sock

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 22

Server version: 8.0.12 MySQL Community Server - GPL

### 3.低版客户端登录异常

错误号码 2058:Plugin caching_sha2_password could not be loaded

SmartyPants将ASCII标点转换为智能印刷标点HTML实体。

原因是mysql8.0 在之前的版本中,加密规则是mysql_native_password,而在mysql之后,加密规则是caching_sha2_password, 有两种方法可以解决这个问题,一种是升级客户端驱动,一种是把mysql还原用户登录密码加密规则mysql_native_password。

如果修改用户密码加密规则可使用如下方式:

1). 修改加密方法:

-- 未过期修改密码

mysql> ALTER USER 'root'@'%' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER;

Query OK, 0 rows affected (0.02 sec)

-- 修改密码并指定加密规则mysql_native_password

mysql> ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';

Query OK, 0 rows affected (0.01 sec)

-- 刷新权限

mysql> flush privileges;

Query OK, 0 rows affected (0.01 sec)

mysql>

修改后再次登录

2).使用高版客户端

linux这种情况也发生在低版客户端登录时,因此需要使用高版客户端

[root@gjc18 lib]# mysql -uroot -p'123456' --socket=/data/mysql/mysql3310/tmp/mysql3310.sock

mysql: [Warning] Using a password on the command line interface can be insecure.

ERROR 2059 (HY000): Authentication plugin 'caching_sha2_password' cannot be loaded: /usr/local/mysql/lib/plugin/caching_sha2_password.so: cannot open shared object file: No such file or directory

[root@gjc18 lib]# /usr/local/mysql8.0/bin/mysql -uroot -p'123456' --socket=/data/mysql/mysql3310/tmp/mysql3310.sock

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 26

Server version: 8.0.12 MySQL Community Server - GPL

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

mysql8.0 zip 免安装版 配置 root 重置 修改 密码 教程

本人使用的mysql最新版本:8.0.20
配置和重置root密码时,遇到了各种问题,在经过各种查阅资料百度后,终于搞定了,下面我们一步步来说明吧。

新安装配置mysql请从头往后看
忘记root如果需要重置密码,请从6.以非安全忽略密码的方式启动mysql(执行后会一直运行)】开始看
文末有说明mysql5.7版本与8.修改密码的区别。

1. 下载mysql
官网太慢了,我自己上传,不要硬币,随便下传

https://blog.csdn.net/guangmo0123/article/details/106207823

2.配置环境变量
将mysql的bin将目录添加到环境变量中path方便后续直接运行mysql的命令。

3.在mysql手动创建根目录ysql的配置文件——my.ini


my.ini内容如下

[mysqld]
# mysql的根目录路径,路径需要使用双斜杠(转义)
basedir=D:\\DevelopIDE\\mysql-8.0.20-winx64
# mysql的数据存放目录,不要手动创建该目录,让mysql初始化时自动创建,文件夹名必须为data
datadir=D:\\DevelopIDE\\mysql-8.0.20-winx64\\data
# mysql的端口号
port=3306
注:各位需要将其中的 basedir 和 datadir 修改为自己的mysql路径

4.以管理员的模式运行cmd(cmd窗口1)初始化mysql
mysqld --initialize
【注】

a.若安装服务时报 vcruntime140_1.dll 找不到的错误,请百度下载【微软常用运行库合集】,然后安装该工具,安装过程中会自动修复运行环境,之后再重新执行初始化命令即可

b.若提示如下错误

mysqld: [ERROR] Found option without preceding group in config file E:\mysql-8.0.16-winx64\my.ini at line 1.

mysqld: [ERROR] Fatal error in defaults handling. Program aborted!

则表示my.ini文件编码格式有误,需要修改为ANSI格式,用记事本打开,另存一下改一下编码格式即可

5.安装mysql服务(安装完成过后,不要启动服务)
mysqld --install
6.以非安全忽略密码的方式启动mysql(cmd执行后,会一直处于运行状态)
mysqld --shared-memory --skip-grant-tables
注:执行此命令(mysqld --shared-memory --skip-grant-tables)前,请先停止mysql服务(net stop mysql)

7.重新开启一个新的cmd窗口(cmd窗口2),直接执行mysql(无需输入root和密码),登录mysql进入命令行状态
mysql
8.使用(选择)mysql这个数据库
use mysql;
9.先清空一下原root的密码(mysql8.0特性)
update user set authentication_string='' where user='root';
10.退出mysql命令行模式
quit
11.退出mysql命令行模式后,就可以关闭所有cmd窗口了
 

12.自此,mysql的密码已经清空了,下次登录时,密码空着不用输入直接回车即可登录
开始设置新密码

1.重新打开新的cmd窗口,启动mysql服务
net start mysql
2.登录mysql,由于上面密码已经清空了,所以密码空着不用数据,直接回车
mysql -uroot -p
3.进入mysql命令行模式后,再设置root新密码
alter user 'root'@'localhost' identified with mysql_native_password by '123456';
注:记得将其中的'123456'修改为自己的密码。另外,如果使用的是网络模式,则可能需要将其中的 'localhost' 换成 '%'

4.自此,mysql的密码已经重置修改成功了
mysql5.7与mysql8.0修改root密码的区别
MySQL 5.7 版本,由于在user表中没有password字段,所以使用下边的方式来修改root密码

update user set authentication_string = password('123456') where user = 'root';
在mysql 5.7.9以后废弃了password字段和password()函数;authentication_string:字段表示用户密码,而authentication_string字段下只能是mysql加密后的41位字符串密码。所以需要用一下方式来修改root密码:

ALTER user 'root'@'localhost' IDENTIFIED BY '123456';
MySql 从8.0开始修改密码有了变化,在user表加了字段authentication_string,修改密码前先检查authentication_string是否为空

如果不为空,需要先将密码清空,之后再设置新密码,建议在执行先,先刷新一下权限,避免出现其它错误

刷新权限

flush privileges;
清空密码

update user set authentication_string='' where user='root';
再设置新密码

alter user 'root'@'localhost' identified with mysql_native_password by '123456';

锐单商城拥有海量元器件数据手册IC替代型号,打造电子元器件IC百科大全!

相关文章