Mysql

無法重置 MySQL 密碼

  • January 1, 2021

我已經堅持了很長時間,我嘗試按照此處的說明進行操作:https ://dev.mysql.com/doc/refman/8.0/en/resetting-permissions.html 。當我執行命令時,我將其作為輸出:

2021-01-01T09:15:04.445377Z 0 [System] [MY-010116] [Server] C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqld.exe (mysqld 8.0.22) starting as process 19920
2021-01-01T09:15:04.487135Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2021-01-01T09:15:04.901676Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2021-01-01T09:15:05.135403Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060
2021-01-01T09:15:05.240496Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2021-01-01T09:15:05.242979Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2021-01-01T09:15:05.325105Z 0 [System] [MY-010931] [Server] C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqld.exe: ready for connections. Version: '8.0.22'  socket: ''  port: 3306  MySQL Community Server - GPL.
2021-01-01T09:15:45.594^C297Z 0 [System] [MY
-013105] [Server] C:C:\Program Files\MySQL\MySQL Server 8.0\bin>\Pro
gram Files\MySQL\MC:\Program Files\MySQL\MySQL Server 8.0\bin>ySQL Server 8.0\bin\mysqld.exe: Normal shutdown.
2021-01-01T09:15:46.281364Z 0 [System] [MY-010910] [Server] C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqld.exe: Shutdown complete (mysqld 8.0.22)  MySQL Community Server - GPL.
mysqld --init-file=C:\Users\user\text.txt --console
2021-01-01T09:15:51.297226Z 0 [System] [MY-010116] [Server] C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqld.exe (mysqld 8.0.22) starting as process 21652
2021-01-01T09:15:51.320019Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2021-01-01T09:15:51.784233Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2021-01-01T09:15:52.015722Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060
2021-01-01T09:15:52.118175Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2021-01-01T09:15:52.126894Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2021-01-01T09:15:52.205977Z 0 [System] [MY-010931] [Server] C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqld.exe: ready for connections. Version: '8.0.22'  socket: ''  port: 3306  MySQL Community Server - GPL.

我不知道從這裡做什麼,因為我不認為它在教程中。任何解決此問題的幫助將不勝感激。謝謝

因為沒有顯示錯誤(但是這個 2021-01-01T09:15:45.594^C297 看起來不正常!),您應該按照過程中所示繼續下一步。

檢查您的密碼是否已更改。

如果您的密碼沒有更改,請創建一個簡單的初始化文件(即與步驟 3 中建議的相同),然後重試。

如果您的密碼已更改,請不要忘記刪除init-file.

編輯

:我按照程序重置了我的“root”密碼。

此會話的所有輸出都在這裡,中間有一些註釋:

首先我們注意到我們不知道密碼:

C:\Program Files\MySQL\MySQL Server 8.0>mysql -u root -p
Enter password: *******
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

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

然後創建一個 mysql-init.txt 文件:

C:\Program Files\MySQL\MySQL Server 8.0>type mysql-init.txt
ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';

然後我們停止 MySQL 伺服器。我的伺服器名為 MySQL80,但您也可以從服務視窗停止它(更多詳細資訊請點擊此處

C:\Program Files\MySQL\MySQL Server 8.0>net stop MySQL80
The MySQL80 service is stopping.
The MySQL80 service was stopped successfully.

密碼重置:

  • 注意路徑名中的雙 \ 和完整路徑周圍的 "
  • 我對 MySQL 的預設設置位於此處“D:\MySQL Server 8.0\my.ini”,這幾乎可以肯定在您所在的位置有所不同
   C:\Program Files\MySQL\MySQL Server 8.0>bin\mysqld.exe --defaults-file="D:\\MySQL Server 8.0\\my.ini" --init-file="C:\\Program Files\\MySQL\\MySQL Server 8.0\\mysql-init.txt" --console
   2021-01-01T18:51:09.333120Z 0 [Warning] [MY-010915] [Server] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.
   2021-01-01T18:51:09.333840Z 0 [System] [MY-010116] [Server] C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqld.exe (mysqld 8.0.22) starting as process 21888
   2021-01-01T18:51:09.341869Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
   2021-01-01T18:51:09.908748Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
   2021-01-01T18:51:10.083573Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060
   2021-01-01T18:51:10.143779Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
   2021-01-01T18:51:10.144078Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
   2021-01-01T18:51:10.192745Z 0 [System] [MY-010931] [Server] C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqld.exe: ready for connections. Version: '8.0.22'  socket: ''  port: 3306  MySQL Community Server - GPL.

現在伺服器啟動並輸出到控制台,停止伺服器類型 CTRL+C:

2021-01-01T18:51:20.697066Z 0 [System] [MY-013105] [Server] C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqld.exe: Normal shutdown.
^C
C:\Program Files\MySQL\MySQL Server 8.0>2021-01-01T18:51:21.447960Z 0 [System] [MY-010910] [Server] C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqld.exe: Shutdown complete (mysqld 8.0.22)  MySQL Community Server - GPL.

我們以正常方式(或通過服務)再次啟動伺服器:

C:\Program Files\MySQL\MySQL Server 8.0>net start mysql80
The MySQL80 service is starting.
The MySQL80 service was started successfully.

我們嘗試登錄:

C:\Program Files\MySQL\MySQL Server 8.0>mysql -u root -pMyNewPass
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 8
Server version: 8.0.22 MySQL Community Server - GPL

Copyright (c) 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> alter user 'root'@'localhost' IDENTIFIED BY 'stackoverflow';

使用最後一條命令,可以將密碼更改為“stackoverflow”。我相信任何讀過這篇文章的人都能想到一個更好的密碼。

引用自:https://dba.stackexchange.com/questions/282426