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窗口无法输入
![在这里插入图片描述](https://img-blog.csdnimg.cn/20181128232358132.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlbnhpdWtla2U=,size_16,color_FFFFFF,t_70)
4. 再开一个DOS窗口,转到mysql\bin目录。
5. 输入mysql回车,如果成功,将出现MySQL提示符 >。
![在这里插入图片描述](https://img-blog.csdnimg.cn/20181128232611568.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlbnhpdWtla2U=,size_16,color_FFFFFF,t_70)
6. 连接权限数据库: use mysql; 。
7. 改密码:update mysql.user set authentication_string='' where user='root';
执行mysql -u root -p直接两次回车,不用输入密码(因为前面设置了空密码)
![在这里插入图片描述](https://img-blog.csdnimg.cn/2018112823331521.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlbnhpdWtla2U=,size_16,color_FFFFFF,t_70)
出现如下信息表示修改成功;
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; 。
![在这里插入图片描述](https://img-blog.csdnimg.cn/20181128233425251.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlbnhpdWtla2U=,size_16,color_FFFFFF,t_70)
9. 退出mysql> quit
10. 注销系统,再进入,使用用户名root和刚才设置的新密码123登录。
## mysql8.0新增用户及密码加密规则修改
MySQL8.0已经发布GA版,当前最新GA版本为8.0.12。虽然相对于之前版本,MySQL8.0没有加入新元素,但是,经过代码重构,MySQL8.0的优化器更加强大,同时也有一些新特性,如支持索引隐藏等。
但是,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)
![在这里插入图片描述](https://img-blog.csdnimg.cn/20181128233919478.png)
### 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
![在这里插入图片描述](https://img-blog.csdnimg.cn/20181128234221452.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlbnhpdWtla2U=,size_16,color_FFFFFF,t_70)
### 3.低版本客户端登录异常
错误号码 2058:Plugin caching_sha2_password could not be loaded
SmartyPants将ASCII标点字符转换为“智能”印刷标点HTML实体。例如:
![在这里插入图片描述](https://img-blog.csdnimg.cn/20181128234352280.png)
出现这个原因是mysql8.0 之前的版本中加密规则是mysql_native_password,而在mysql8之后,加密规则是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>
修改完毕后再次登录即可成功
![在这里插入图片描述](https://img-blog.csdnimg.cn/20181128234536409.png)
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.
网友评论