MySQL8.0以上版本正确修改密码方式详解

MySQL8.0+版本修改密码

大致步骤:

1、停止 MySQL 任务===> net stop MySQL

2、启动mysqld服务===> mysqld --console --skip-grant-tables --shared-memory

3、无密码进入mysql===>mysql -u root

4、清空root 密码 ===>UPDATE user SET authentication_string="" WHERE user=“root”;

5、停止 mysqld 任务===>Ctrl+C 结束任务,或者直接关闭 运行 mysqld 的 cmd 终端。

6、启动mysql===>net start mysql

7、登录 不输密码===>mysql -u root -p

8、修改密码===>alter user’root’@‘localhost’ identified with mysql_native_password by ‘新密码’;

详细步骤:

注:CMD控制台均用管理员身份运行
1、停止MySQL
MySQL8.0以上版本正确修改密码方式详解
2、CMD内输入:mysqld --console --skip-grant-tables --shared-memory
然后保留此窗口,以管理员身份新开一个CMD。
MySQL8.0以上版本正确修改密码方式详解
3、无密码进入mysql,在新的CMD内输入:mysql -u root
注:root为我的mysql用户名
MySQL8.0以上版本正确修改密码方式详解
4、清空root 密码:USE mysql;
UPDATE user SET authentication_string="" WHERE user=“root”;
MySQL8.0以上版本正确修改密码方式详解
5、停止mysqld任务:Ctrl+C 结束之前保留的CMD,或者直接关闭 运行 mysqld 的 cmd 终端。

6、新开一个CMD,启动mysql:net start mysql
MySQL8.0以上版本正确修改密码方式详解
7、不输入密码登录mysql:mysql -u root -p
MySQL8.0以上版本正确修改密码方式详解
8、修改密码:use mysql;
alter user’root’@‘localhost’ identified with mysql_native_password by ‘新密码’;
MySQL8.0以上版本正确修改密码方式详解

完成;
别忘重新编辑Navicat等软件的连接