When attempting to connect to a MySQL database from PHP, you might encounter the error: "The server requested authentication method unknown to the client." This issue stems from the authentication plugin used by MySQL.
By default, MySQL 8 utilizes the auth_socket plugin, which is not compatible with applications expecting a password-based login. To rectify this, follow these steps:
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
Replace 'password' with the desired password for the root user. If your application does not use the root user, substitute 'root' with the relevant username.
Once these changes are implemented, applications should be able to connect to the MySQL database using a password. For further details, refer to the Digital Ocean documentation: https://www.digitalocean.com/community/tutorials/how-to-install-mysql-on-ubuntu-18-04.
The above is the detailed content of How to Fix 'The server requested authentication method unknown to the client' Error in PHP MySQL 8.0 ?. For more information, please follow other related articles on the PHP Chinese website!