The server requested authentication method unknown to the client

Posted jdcai

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了The server requested authentication method unknown to the client相关的知识,希望对你有一定的参考价值。

SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client.

In mysql 8.0+, the default authentication plugin has changed from ‘mysql_native_password‘ to ‘caching_sha2_password‘, and the ‘root‘@‘localhost‘ administrative account uses the ‘caching_sha2_password‘ authentication plugin by default. If you prefer that the root account use the previous default authentication plugin ‘mysql_native_password‘.

The PDO_MySQL and ext/mysqli extensions of php do not support caching_sha2_password. In addition, when PHP MySQL extensions used with PHP versions before 7.1.16 and PHP 7.2 before 7.2.4, they fail to connect with default_authentication_plugin=caching_sha2_password even if caching_sha2_password is not used. However the X DevAPI PHP extension (mysql_xdevapi) supports it.

To restore MySQL pre-8.0 compatibility, you can reconfigure the server to revert to the previous default authentication plugin mysql_native_password like:

  1. [mysqld]
  2. default_authentication_plugin=mysql_native_password
复制代码

Restart the MySQL database, the problem should be solved, otherwise you may need to reinitialize the MySQL installation data and reinstall it.

You can connect to the MySQL database using mysql commandline utility, and then create a new user with the older mysql_native_password plugin with SQL.

  1. mysql -uroot -p
  1. CREATE USER ‘WUXIANCHENG‘ IDENTIFIED WITH ‘mysql_native_password‘ BY ‘YOUR_PASSWORD_IN_TRANSPARENT_TEXT‘;
  2. GRANT ALL PRIVILEGES ON *.* TO ‘WUXIANCHENG‘@‘%‘;

Now you can connect to the MySQL database in PHP using the newly created account. You can also change existing users‘ authentication plugin after connecting to the MySQL database with the new account.

  1.  use mysql;
  2. UPDATE `user` SET `Host`=‘%‘ WHERE `User`=‘root‘;
  3. ALTER USER ‘root‘ IDENTIFIED WITH ‘mysql_native_password‘ BY ‘YOUR_PASSWORD_IN_TRANSPARENT_TEXT‘;     
 

If the default root user was restricted to localhost, the ALTER USER statment will fail with message like "ERROR 1396 (HY000): Operation ALTER USER failed for ‘root‘@‘%‘", so you have to change Host from localhost to % first.
Dont‘ forget to replace YOUR_PASSWORD_IN_TRANSPARENT_TEXT with your own password!












以上是关于The server requested authentication method unknown to the client的主要内容,如果未能解决你的问题,请参考以下文章

The server requested authentication method unknown to the client

Error from server (NotFound): the server could not find the requested resource (get services http:he

Unable to make the session state request to the session state server处理

Unable to make the session state request to the session state server处理方法

转: 解决Unable to make the session state request to the session state server

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