php mysqli_connect: Authentication Method Caching_sha2_Password Issue on MySQL Server
Problem:
When attempting to connect to a MySQL database using mysqli_connect on localhost, the following error occurs: "mysqli_connect(): The server requested authentication method unknown to the client [caching_sha2_password]". This issue arises when using the caching_sha2_password authentication plugin on the MySQL server.
Solution:
To resolve this authentication method conflict, follow these steps:
ALTER USER 'username'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
CREATE USER 'username'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
By implementing these changes, your MySQL server will be configured to use the mysql_native_password authentication plugin, making it compatible with the mysqli_connect function and allowing for successful database connections.
The above is the detailed content of How to Fix 'mysqli_connect(): The server requested authentication method unknown to the client [caching_sha2_password]' Error?. For more information, please follow other related articles on the PHP Chinese website!