php mysqli_connect: authentication method unknown to the client [caching_sha2_password]

前端 未结 11 2224
遥遥无期
遥遥无期 2020-11-22 03:40

I am using php mysqli_connect for login to a MySQL database (all on localhost)



        
相关标签:
11条回答
  • 2020-11-22 03:54

    If you're on Windows and it's not possible to use caching_sha2_password at all, you can do the following:

    1. rerun the MySQL Installer
    2. select "Reconfigure" next to MySQL Server (the top item)
    3. click "Next" until you get to "Authentication Method"
    4. change "Use Strong Password Encryption for Authentication (RECOMMENDED)" to "Use Legacy Authentication Method (Retain MySQL 5.X Compatibility)
    5. click "Next"
    6. enter your Root Account Password in Accounts and Roles, and click "Check"
    7. click "Next"
    8. keep clicking "Next" until you get to "Apply Configuration"
    9. click "Execute"

    The Installer will make all the configuration changes needed for you.

    0 讨论(0)
  • 2020-11-22 03:55
    ALTER USER 'mysqlUsername'@'localhost' IDENTIFIED WITH mysql_native_password BY 'mysqlUsernamePassword';
    

    Remove quotes (') after ALTER USER and keep quote (') after mysql_native_password BY

    It is working for me also.

    0 讨论(0)
  • 2020-11-22 03:57

    I solve this by SQL command:

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

    which is referenced by https://dev.mysql.com/doc/refman/8.0/en/alter-user.html

    if you are creating new user

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

    which is referenced by https://dev.mysql.com/doc/refman/8.0/en/create-user.html

    this works for me

    0 讨论(0)
  • 2020-11-22 03:57

    Like many many people, I have had the same problem. Although the user is set to use mysql_native_password, and I can connect from the command line, the only way I could get mysqli() to connect is to add

    default-authentication-plugin=mysql_native_password

    to the [mysqld] section of, in my setup on ubuntu 19.10, /etc/mysql/mysql.conf.d/mysqld.cnf

    0 讨论(0)
  • 2020-11-22 04:03

    I tried this in Ubuntu 18.04 and is the only solution that worked for me:

    ALTER USER my_user@'%' IDENTIFIED WITH mysql_native_password BY 'password';
    
    0 讨论(0)
  • 2020-11-22 04:04

    I ran the following command ALTER USER 'root' @ 'localhost' identified with mysql_native_password BY 'root123'; in the command line and finally restart MySQL in local services.

    0 讨论(0)
提交回复
热议问题