MySQL 8下忘密碼後重置密碼的辦法和Navicat報1521錯誤
阿新 • • 發佈:2018-12-10
MySQL 8下忘密碼後重置密碼的辦法
第一步,關掉系統服務
net stop mysql
第二步,建立一個文字檔案,內含一條密碼修改命令(''中間可以填寫修改後的密碼)
ALTER USER 'root'@'localhost' IDENTIFIED BY '';
第三步:命令列方式啟動伺服器,指定啟動時執行上述的密碼修改命令檔案
mysqld --init-file=d:\mysql\c.txt --console
具體操作截圖
Navicat報1521錯誤
無法連線的原因是mysql8與mysql5的加密方式不同。
連線時會出現1251錯誤。
解決辦法:
1.先通過命令列進入mysql的root賬戶:
<code class="language-plain">PS C:\Windows\system32> mysql -uroot -p</code>
再輸入root的密碼:
Enter password: ****** Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 18 Server version: 8.0.11 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. mysql>
2.更改加密方式:
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER;
Query OK, 0 rows affected (0.10 sec)
3.更改密碼:
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
Query OK, 0 rows affected (0.35 sec)
4.重新整理:
mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.28 sec)
// 如果報錯 ERROR 1396 (HY000): Operation ALTER USER failed for 'root'@'%' :
則是遠端訪問許可權不正確,先選擇資料庫,檢視一下再更改:
mysql> use mysql;
Database changed
mysql> select user,host from user;
+------------------+-----------+
| user | host |
+------------------+-----------+
| mysql.infoschema | localhost |
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
+------------------+-----------+
5 rows in set (0.00 sec)
文章參考: