I'm using phpmysqli_connect
Login to MySQL database (all on localhost)
This is the mysql.user table:
MySQL server ini file:
[mysqld] # The default authentication plugin to be used when connecting to the server default_authentication_plugin=caching_sha2_password #default_authentication_plugin=mysql_native_password
Usingcaching_sha2_password
in the MySQL Server ini file, it is impossible to log in with user1 or user2;
Error: mysqli_connect(): Server requested client [caching_sha2_password] unknown authentication method...
Usingmysql_native_password
in the MySQL Server ini file, you can log in with user1, but the same error occurs with user2;
How to log in usingcaching_sha2_password
on mySql server?
I solved this problem via SQL command:
Referenced byhttps://dev.mysql. com/doc/refman/8.0/en/alter-user.html
If you are creating a new user
Referenced byhttps://dev.mysql. com/doc/refman/8.0/en/create-user.html
This worked for me
As of PHP 7.4, this is no longer a problem. mysqlnd added support for the
caching_sha2
authentication method.Currently, the new caching_sha2 authentication feature is not supported by the PHP mysqli extension. You'll have to wait until they release an update.
View related posts from MySQL developers:https: //mysqlserverteam.com/upgrading-to-mysql-8-0-default-authentication-plugin-considerations/
They don't mention PDO, maybe you should try using PDO connection.