PHP With MySQL 8.0+ Error: The Server Requested Authentication Method Unknown To The Client

This error typically occurs when you are trying to connect to a MySQL server using PHP, but the authentication method being used by the server is not supported by the client.

To resolve this issue, you can try one of the following solutions:

  1. Upgrade your PHP version: The first thing you can do is make sure you are using the latest version of PHP. Older versions may not support the authentication method used by MySQL 8.0+. Upgrade to a newer version of PHP that includes support for the required authentication method.

  2. Change the authentication method: If upgrading PHP is not an option, you can change the authentication method used by the MySQL server. You can do this by modifying the MySQL configuration file (my.cnf) and adding the following line under the [mysqld] section:


    After making this change, restart the MySQL server for the changes to take effect.

  3. Use a compatible authentication method: If changing the authentication method is not possible, you can try using a different authentication method that is supported by both PHP and MySQL. One such method is the caching_sha2_password authentication method. To use this method, you need to modify the MySQL user’s authentication plugin. You can do this by running the following SQL query:

    ALTER USER ‘username’@’hostname’ IDENTIFIED WITH caching_sha2_password BY ‘password’;

    Replace ‘username’, ‘hostname’, and ‘password’ with your actual values. Once the user’s authentication plugin is changed, you should be able to connect to the MySQL server using PHP.

Remember to restart the MySQL server and test your PHP connection after making any changes.

About the Author Rex

I'm a passionate tech blogger with an insatiable love for programming! From my early days tinkering with code, I've delved into web dev, mobile apps, and AI. Sharing insights and tutorials with the world is my joy, connecting me to a global community of like-minded tech enthusiasts. Python holds a special place in my heart, but I embrace all challenges. Constantly learning, I attend tech conferences, contribute to open-source projects, and engage in code review sessions. My ultimate goal is to inspire the next generation of developers and contribute positively to the ever-evolving tech landscape. Let's code together!