mysql8.0重置密码流程-win10

参考mysql 8.0以上重置密码,添加自己遇到的更多坑。

MYSQL 重置密码

    • 0 全部都以管理员的身份运行
    • 1 进bin目录
    • 2 停止mysql服务
      • 2.1 服务名无效
    • 3 启动MySQL服务的时候跳过权限表认证
      • 3.1 报错 Failed to set datadir to 'C:\Program Files\MySQL\MySQL Server 8.0\data\' (OS errno: 2 - No such file or directory)
    • 4 新开命令行,启动mysql
    • 5 清空root密码
    • 6 重启mysql服务
    • 7 进入mysql
    • 8 修改密码
    • 9 使用新密码登录
  • THE END

0 全部都以管理员的身份运行

1 进bin目录

win10可以Cortana搜mysql shell,然后一路“打开文件所在位置”

cd C:\Program Files\MySQL\MySQL Server 8.0\bin

2 停止mysql服务

net stop mysql

2.1 服务名无效

cmd中输入net start mysql 提示:服务名无效或者MySQL正在启动 MySQL无法启动

先进bin目录

cd C:\Program Files\MySQL\MySQL Server 8.0\bin

在命令行中输入

mysqld --install

成功:出现Service successfully install代表你已经安装成功

3 启动MySQL服务的时候跳过权限表认证

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

3.1 报错 Failed to set datadir to ‘C:\Program Files\MySQL\MySQL Server 8.0\data’ (OS errno: 2 - No such file or directory)

2020-06-27T10:35:55.418234Z 0 [System] [MY-010116] [Server] C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqld.exe (mysqld 8.0.20) starting as process 7356
2020-06-27T10:35:55.421333Z 0 [Warning] [MY-010091] [Server] Can’t create test file C:\Program Files\MySQL\MySQL Server 8.0\data\mysqld_tmp_file_case_insensitive_test.lower-test
2020-06-27T10:35:55.421408Z 0 [Warning] [MY-010091] [Server] Can’t create test file C:\Program Files\MySQL\MySQL Server 8.0\data\mysqld_tmp_file_case_insensitive_test.lower-test
2020-06-27T10:35:55.421583Z 0 [ERROR] [MY-013276] [Server] Failed to set datadir to ‘C:\Program Files\MySQL\MySQL Server 8.0\data’ (OS errno: 2 - No such file or directory)
2020-06-27T10:35:55.455606Z 0 [ERROR] [MY-010119] [Server] Aborting
2020-06-27T10:35:55.455799Z 0 [System] [MY-010910] [Server] C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqld.exe: Shutdown complete (mysqld 8.0.20) MySQL Community Server - GPL.

参考资料

解决[ERROR] [MY-013276] [Server] Failed to set datadir to ‘F:\Mysql\mysql-8.0.19-winx64\data’ (OS er

mysqld --initialize --user=mysql --console

2020-06-27T11:12:41.246262Z 0 [System] [MY-013169] [Server] C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqld.exe (mysqld 8.0.20) initializing of server in progress as process 13880
2020-06-27T11:12:41.263871Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2020-06-27T11:12:42.438142Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2020-06-27T11:12:44.227965Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: sXrsP9:qx3SR

mysqld -install

The service already exists!
The current server installed: “C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqld” MySQL

sc delete mysql

[SC] DeleteService 成功

mysqld -install

Service successfully installed.

net start mysql

MySQL 服务正在启动 .
MySQL 服务已经启动成功。

net stop mysql

MySQL 服务正在停止.
MySQL 服务已成功停止。

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

2020-06-27T11:17:46.374142Z 0 [System] [MY-010116] [Server] C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqld.exe (mysqld 8.0.20) starting as process 3976
2020-06-27T11:17:46.390118Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2020-06-27T11:17:47.007918Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2020-06-27T11:17:47.278043Z 0 [Warning] [MY-011311] [Server] Plugin mysqlx reported: ‘All I/O interfaces are disabled, X Protocol won’t be accessible’
2020-06-27T11:17:47.441694Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2020-06-27T11:17:47.494282Z 0 [System] [MY-010931] [Server] C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqld.exe: ready for connections. Version: ‘8.0.20’ socket: ‘’ port: 0 MySQL Community Server - GPL.

这样就是已经启动了,保持这个命令行不动

4 新开命令行,启动mysql

进bin,开mysql

cd C:\Program Files\MySQL\MySQL Server 8.0\bin
mysql

Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 8.0.20 MySQL Community Server - GPL

Copyright © 2000, 2020, 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>

5 清空root密码

use mysql;
update user set authentication_string = '' where user='root' ;

Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0

quit;

Bye

6 重启mysql服务

在之前的命令行将我们开启的mysql服务停止掉

(Ctrl+C多点几次)

然后执行

net start mysql 

7 进入mysql

输入

mysql -uroot -p 

无需输入密码,直接按enter键(这里密码已经被清空)

Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.20

Copyright © 2000, 2020, 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>

8 修改密码

ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';      

Query OK, 0 rows affected (0.01 sec)

quit;

Bye

9 使用新密码登录

mysql -uroot -p

输入新密码即可

THE END

你可能感兴趣的:(mysql)