mysql8.0出現(xiàn)的2059 - authentication plugin 'caching_sha2_password' -navicat連接異常問題
問題描述:
在navicat鏈接mysql8以后的版本時會出現(xiàn)2059的錯誤烟勋,這個錯誤出現(xiàn)的原因是在mysql8之前
的版本中加密規(guī)則為mysql_native_password
乏冀,而在mysql8以后
的加密規(guī)則為caching_sha2_password
歉甚。
解決方案:
- 將mysql8.0以后驗(yàn)證方式改為以前版本使用的驗(yàn)證方式
mysql_native_password
。
找到mysql對應(yīng)的安裝目錄下my-default.ini
文件戒傻,
將default_authentication_plugin=caching_sha2_password
改為default_authentication_plugin=mysql_native_password
。
以下是我的my-default.ini
的內(nèi)容:[mysqld] # 設(shè)置3306端口 port=3306 # 設(shè)置mysql的安裝目錄 basedir=C:\Program Files\MySQL\MySQL Server 8.0 # 設(shè)置mysql數(shù)據(jù)庫的數(shù)據(jù)的存放目錄 datadir=C:\Program Files\MySQL\MySQL Server 8.0\data # 允許最大連接數(shù) max_connections=200 # 允許連接失敗的次數(shù)蜂筹。這是為了防止有人從該主機(jī)試圖攻擊數(shù)據(jù)庫系統(tǒng) max_connect_errors=10 # 服務(wù)端使用的字符集默認(rèn)為UTF8 character-set-server=utf8 # 創(chuàng)建新表時將使用的默認(rèn)存儲引擎 default-storage-engine=INNODB # 默認(rèn)使用“mysql_native_password”插件認(rèn)證 default_authentication_plugin=mysql_native_password [mysql] # 設(shè)置mysql客戶端默認(rèn)字符集 default-character-set=utf8 [client] # 設(shè)置mysql客戶端連接服務(wù)端時默認(rèn)使用的端口 port=3306 default-character-set=utf8
- 以
管理員身份
運(yùn)行cmd(win10右鍵左下角開始按鈕選擇以管理員身份運(yùn)行cmd即可) - 以管理員身份運(yùn)行cmd進(jìn)入mysql的安裝目錄下的bin文件夾
C:\>cd C:\Program Files\MySQL\MySQL Server 8.0\bin
- 如果C:\Program Files\MySQL\MySQL Server 8.0\bin 目錄下沒有data文件夾需纳,執(zhí)行以下命令:
- 輸入
mysqld -install
(如果不用管理員身份運(yùn)行,將會因?yàn)闄?quán)限不夠而出現(xiàn)錯誤:Install/Remove of the Service Denied!) - 運(yùn)行
mysqld --initialize
即可狂票,此時查看已有data文件夾候齿。
- 輸入
- 登錄數(shù)據(jù)庫
命令行執(zhí)行mysql -u root -p
然后輸入數(shù)據(jù)庫密碼,出現(xiàn)Welcome to the MySQL monitor. .. 字樣則登錄成功闺属。 - 修改加密規(guī)則
執(zhí)行ALTER USER 'root'@'localhost' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER;
- 更新一下用戶的密碼
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'xxxxx';
其中的xxxxx 為新設(shè)置的密碼慌盯。 - 刷新權(quán)限
執(zhí)行FLUSH PRIVILEGES; - 然后打開Navicat連接Mysql,發(fā)現(xiàn)連接成功了掂器,完美解決問題亚皂。
- 具體操作如下:
C:\>cd C:\Program Files\MySQL\MySQL Server 8.0\bin C:\Program Files\MySQL\MySQL Server 8.0\bin>mysql -u root -p Enter password: ****** Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8 Server version: 8.0.13 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> ALTER USER 'root'@'localhost' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER; Query OK, 0 rows affected (0.07 sec) mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'abcd'; Query OK, 0 rows affected (0.06 sec) mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.00 sec) mysql>
經(jīng)過一系列操作最終解決了問題,Navicat順利連接Mysql国瓮。