PHP Error: sqlstate[hy000] [2054] The server requested authentication method unknown to the client

Source: Internet
Author: User
Tags php error



When using PHP to connect to MySQL 8, the error as shown in the title may occur:


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


This error occurs because MySQL 8 defaults to using the new password Authentication plugin: Caching_sha2_password, and the mysqlnd that was in the previous PHP version did not support this validation. There are two ways to solve this problem.



One way is to upgrade PHP to support MySQL 8 's new authentication plugin.



PHP 7.2.8 and PHP 7.1.20 have been able to support Caching_sha2_password, directly connected to MySQL 8.



As of PHP 7.0.31 and PHP 5.6.37, it is not possible to support Caching_sha2_password, and it is not known whether subsequent versions will support it.



You can find out whether the currently installed PHP supports Caching_sha2_password by using the Phpinfo () function:






If you cannot upgrade PHP, you can create (or modify) an account using the Caching_sha2_password plugin in MySQL 8 to use Mysql_native_password so that previous versions of PHP can be connected.


  1. When you create user, use identified with Xxx_plugin by ' password ', such as:
  2. CREATE USER ' native '@'localhost'with by'password!2#4 ';
  3. Use ALTER user to modify the validation plugin for an existing account:
    ALTER USER ' native '@'localhost' with Mysql_native_password


    Or


    ALTER USER ' native '@'localhost'with by'new_password ';


    In the previous way, the password for the account will be cleared; The BY clause will set a new password for the account.


  4. In the/ETC/MY.CNF configuration file, there is a line:
  5. # Default-authentication-plugin=mysql_native_password

    Please delete the comment symbol "#" and restart Mysqld for it to take effect, and the account created thereafter will use Mysql_native_password by default.

  6. If you complete the installation of MySQL server and modify the/ETC/MY.CNF configuration without starting the MYSQLD service, then the ' root ' @ ' localhost ' account created after the mysqld is started is also used Mysql_native_ Password plug-in.


In this respect, hope is helpful.



PHP Error: sqlstate[hy000] [2054] The server requested authentication method unknown to the client


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.