0

I want to connect mysql 8 to php 7.2, but always get error:

The server requested authentication method unknown to the client [caching_sha2_password]

I have altered the user to use the mysql_native_password plugin. But still can not connect.

ALTER USER 'root'@'localhost'
  IDENTIFIED WITH mysql_native_password
             BY 'root';

Do you have the solution?

Thanks,

Siva
  • 1,481
  • 1
  • 18
  • 29
Abdul
  • 1
  • 2
  • 1
    Does this answer your question? [php mysqli\_connect: authentication method unknown to the client \[caching\_sha2\_password\]](https://stackoverflow.com/questions/50026939/php-mysqli-connect-authentication-method-unknown-to-the-client-caching-sha2-pa) – Martin Feb 28 '20 at 21:03

1 Answers1

0

The way I solved this is by re-initializing the database and switch to 'Use Legacy Password Encryption'.

MacOS X:

  1. Click the Apple icon > System preferences > MySQL

  2. Stop MySQL Server

  3. Initialize Database

  4. Use Legacy Password Encryption > Save

  5. Start MySQL Server

Screenshot

PelleLV
  • 1,031
  • 9
  • 10
  • In step 4 above, where do you see the option to "Use Legacy Password Encryption > Save?" – James Feb 28 '20 at 20:30
  • 1
    Edited my original answer and added a screenshot. Let me know if that helped. – PelleLV Feb 29 '20 at 21:38
  • Yes, that helps. However, it doesn't look like mine. My MySQL System Preference does not offer that option. Where did you get mysql from? I downloaded MySQL 8.0.19 from https://dev.mysql.com/downloads/ – James Feb 29 '20 at 23:18
  • I figured out why I don't have that option in my MySQL System Preference. When you do "Initialize Database" it will read the /etc/my.cnf file first and if the directive to use the old authentication plugin already exists ( default_authentication_plugin=mysql_native_password ), you will not be presented with the option to choose. – James Mar 01 '20 at 00:14