PHP Warning: mysqli_connect(): The server requested authentication method unknown to the client

PHP Warning: mysqli_connect(): The server requested authentication method unknown to the client [caching_sha2_password] in /usr/local/php/CreateDB.php on line 5

mysql 安裝了最新版本8.0.11後創建用戶並授權後,授權的用戶連接數據庫提示

The server requested authentication method unknown to the client

查閱一些相關的資料後發現是由於新版本的mysql賬號密碼解鎖機制不一致導致的

 mysql 8 升級了密碼的驗證方式 caching_sha2_password, 之前一直是mysql_native_password方式

解決辦法:

方法一:

刪除創建的用戶和授權,

找到mysql配置文件並加入

 default_authentication_plugin=mysql_native_password

變爲原來的驗證方式,然後從新創建用戶並授權即可

方法二:

mysql -uroot -p

use mysql;

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '你的密碼';

然後重啓 mysql 即可

mysql.server restart

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章