无法在 Windows 上重新安装 MySql "Could not connect to MySql with the given password"。忘记根密码

Cannot reinstall MySql "Could not connect to MySql with the given password" on Windows. Forgot root password

我正在学习Spring批处理。我按照说明安装 MySQL Shell 8.0.26 以及 Workbench 8.0 on Windows 11.

不过我得到

MySQL  JS > alter user 'root'@'localhost' IDENTIFIED WITH mysql_native_password by 'password';
SyntaxError: Unexpected identifier
 MySQL  JS > show schemas;
SyntaxError: Unexpected identifier
 MySQL  JS > show databases;

所以我尝试卸载并重新安装 MySql。 当我 运行 安装程序时,

我忘记了root密码。我该怎么办?

在此 similar SO 问题中,此人记住了密码。

我进行了互联网搜索并尝试按照此处的步骤进行操作

https://dev.mysql.com/doc/refman/5.7/en/resetting-permissions.html

C:\Program Files\MySQL\MySQL Server 8.0\bin>.\mysqld --init-file=C:\Documents\mysql-init.txt
2021-11-15T00:37:15.052478Z 0 [System] [MY-010116] [Server] C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqld.exe (mysqld 8.0.26) starting as process 5260
2021-11-15T00:37:15.054496Z 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
2021-11-15T00:37:15.054535Z 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
2021-11-15T00:37:15.054651Z 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)
2021-11-15T00:37:15.056382Z 0 [ERROR] [MY-010119] [Server] Aborting
2021-11-15T00:37:15.056496Z 0 [System] [MY-010910] [Server] C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqld.exe: Shutdown complete (mysqld 8.0.26)  MySQL Community Server - GPL.

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

我找到这篇文章,它说必须手动删除以下文件夹。仅从 Windows 控制面板卸载是不够的。

C:\Program Files\MySQL

C:\Program Files (x86)\MySQL

C:\ProgramData\MySQL

https://answers.microsoft.com/en-us/windows/forum/windows_other-windows_programs/how-to-completely-uninstall-mysql/e90e1344-7b90-4319-8b2f-77b271ae66ed

我按照步骤操作,当我再次 运行 安装程序时,它要求输入新的 root 密码!