phpmysqlsha2abyss

How to fix HY000/2054 when implementing MySQL with Abyss Web Server?


I'm starting up a web server using Abyss X1, and just tried implementing a MySQL server through PHP with the following two scripts:

connect_db.php :

#Connect on 'localhost' for user 'admin'
#with password 'RoboticCowboy2019' to database 'site_db'.
$dbc = mysqli_connect
 ( 'localhost' , 'admin', 'password', 'site_db' )
OR die
 ( mysqli_connect_error() );

#Set encoding to match PHP script encoding.
mysqli_set_charset($dbc, 'utf8' );

and

require.php :

#Incorporate the MySQL connection script.
require ('../connect_db.php');

#Display MySQL version and host.
if(mysqli_ping($dbc)){
    echo 'MySQL Server'.mysqli_get_server_info($dbc).'on'.mysqli_get_host_info($dbc);
}

However, when I go to http://localhost/require.php, I get these errors:

"Warning: mysqli_connect(): The server requested authentication method unknown to the client [caching_sha2_password] in /Applications/Abyss Web Server/connect_db.php on line 6"

"Warning: mysqli_connect(): (HY000/2054): The server requested authentication method unknown to the client in /Applications/Abyss Web Server/connect_db.php on line 6 The server requested authentication method unknown to the client"

I'm following the instructions of a book that I know is outdated, but I've been able to get around every problem until now. I've also read that it has something to do with MySQL updating and implementing sha2, while PHP still does not? I'm doing this for my compsci class, so I'd appreciate all the help I can get.

Thank you!


Solution

  • Alter the user

    ALTER USER 'mysqluser'@'localhost' IDENTIFIED WITH mysql_native_password BY 'mysqlpassword';
    

    or use

    shell>mysql --default-auth=mysql_native_password