The server requested authentication method unknown to the client in MySQL 8

Hello guys,
Today, I got another error when I tried to run migrate artisan command in Laravel. The error said: “The server requested authentication method unknown to the client”. This error appeared after I upgraded MySQL server from 5.7 to latest version as known 8.0.

By default, for some reasons, the default plugin of MySQL 8 is auth_socket. So the Applications will most times expect to log in to your database using a password. If you have not changed your mysql default authentication plugin yet, you can do these:

I have to change MySQL configuration. I edited the my.cnf file and put this line right below the [mysqld] like this.

[mysqld]
default_authentication_plugin= mysql_native_password

Then, I logged in the MySQL as root. Next, I ran these commands in the terminal.

ALTER USER 'admin' IDENTIFIED WITH mysql_native_password BY 'secret';
FLUSH PRIVILEGES;

Replace “secret” with your root password. In case your application does not log in to your database with the root user, replace the “admin” user in the above command with the user that your application uses.