uthentication to host '10.0.1.33' for user 'root' using method 'mysql_native_password' failed with message: Access denied for user 'root'@'PCName' (using password: YES)


string conDBstring = "Server=" + server + ";Uid=" + userName + ";Pwd=" + passWord + ";Database=test_db";
MySqlConnection con = new MySqlConnection(conDBstring);

con.Open();

連接mysql數據時,本機Server寫localhost或10.0.1.33都可以連上,但是局域網其他電腦填10.0.1.33正確的用戶名密碼就報標題中的錯誤

 

需要給當前數據庫開啟遠程權限才行,命令如下:

grant all privileges on *.* to 'root'@'%' identified by 'YourPassword' with grant option; 

 

 

 

 

在MySQL 5.5.62里按上圖輸入沒問題,但是后來在MySQL 8.0.18里輸入上面命令會報錯

 

 

 

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version
for the right syntax to use near 'IDENTIFIED BY '123456' WITH GRANT OPTION' at line 1

 

 

此時用C# MySqlConnection連接,會報錯:

Authentication method 'caching_sha2_password' is not supported.

 

原因:mysql版本身份驗證引起的,

官網解釋:https://dev.mysql.com/doc/refman/8.0/en/caching-sha2-pluggable-authentication.html

 

解決方法:

mysql安裝目錄下修改my.ini文件(如果沒有就新建一個my.ini),設置mysql_native_password為默認身份驗證方式

[mysqld]
default_authentication_plugin=mysql_native_password

其他設置項可參考官方文檔

 

 

 

 

參考:

mysql Access denied for user 'root'@'localhost' (using password: YES)

Authentication plugin 'caching_sha2_password' is not supported問題

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM