php mysqli_connect: Authentication method unknown to client
P粉170858678
P粉170858678 2023-10-13 18:02:37
0
2
541

I'm using phpmysqli_connectLogin 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_passwordin 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_passwordin the MySQL Server ini file, you can log in with user1, but the same error occurs with user2;


How to log in usingcaching_sha2_passwordon mySql server?

P粉170858678
P粉170858678

reply all (2)
P粉727416639

I solved this problem via SQL command:

ALTER USER 'mysqlUsername'@'localhost' IDENTIFIED WITH mysql_native_password BY 'mysqlUsernamePassword';

Referenced byhttps://dev.mysql. com/doc/refman/8.0/en/alter-user.html

If you are creating a new user

CREATE USER 'jeffrey'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';

Referenced byhttps://dev.mysql. com/doc/refman/8.0/en/create-user.html

This worked for me

    P粉225961749

    As of PHP 7.4, this is no longer a problem. mysqlnd added support for thecaching_sha2authentication 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.

      Latest Downloads
      More>
      Web Effects
      Website Source Code
      Website Materials
      Front End Template
      About us Disclaimer Sitemap
      php.cn:Public welfare online PHP training,Help PHP learners grow quickly!