When attempting to connect to a MySQL database from PHP, an error may arise stating: "The server requested authentication method unknown to the client." This error typically pertains to an incompatible authentication plugin utilized by MySQL.
MySQL 8.0 employs the "caching_sha2_password" authentication plugin by default, which conflicts with PHP applications that anticipate password-based login. Consequently, you must modify the MySQL authentication plugin to suit the authentication method expected by your PHP application.
To alter the authentication plugin in MySQL:
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'new_password';
Substitute "new_password" with the desired root password. If your PHP application utilizes a non-root user, replace "root" with that specific username.
For additional information on this topic, refer to the comprehensive guide provided by Digital Ocean at:
https://www.digitalocean.com/community/tutorials/how-to-install-mysql-on-ubuntu-22-04-focal-fossa
By implementing these steps, you can effectively resolve the "The server requested authentication method unknown to the client" error and seamlessly establish connections between your PHP application and MySQL database.
The above is the detailed content of How to Fix the 'Server Requested Authentication Method Unknown to Client' Error in PHP with MySQL 8.0 ?. For more information, please follow other related articles on the PHP Chinese website!