Home >Backend Development >PHP Tutorial >How to Fix 'The server requested authentication method unknown to the client' Error in PHP MySQL 8.0 ?

How to Fix 'The server requested authentication method unknown to the client' Error in PHP MySQL 8.0 ?

Susan Sarandon
Susan SarandonOriginal
2024-12-06 11:40:14732browse

How to Fix

Resolving Authentication Error in PHP with MySQL 8.0

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:

  1. Log into the MySQL server as the root user.
  2. Execute the following SQL command:
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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn