首页 > 解决方案 > PHP,MySQL 返回“连接失败:服务器请求客户端未知的身份验证方法”

问题描述

尝试连接到本地 Mysqli DB。

数据库连接: <?php $con= new mysqli("localhost","Kobe24","Kobei987","Bkn_Data"); if ($con->connect_error) { die("Connection failed: " . $con->connect_error); }

返回这个: Warning: mysqli::__construct(): (HY000/2054): The server requested authentication method unknown to the client in C:\Apache24\htdocs\poc\practice_project\database_connection.php on line 1 Connection failed: The server requested authentication method unknown to the client

任何反馈都会有所帮助。一直在研究这个问题,但没有明确的解决方案。

标签: phpmysqli

解决方案


你能按照下面的代码试试这个mysqli_connect()函数吗?还请确保数据库用户和密码正确,并且该用户具有连接数据库的权限

<?php
         $dbhost = 'localhost:3306';
         $dbuser = 'enter database user';
         $dbpass = 'enter password';
         $con = mysqli_connect($dbhost, $dbuser, $dbpass);

         if(! $con ){
            die('Could not connect: ' . mysqli_error());
         }
         echo 'Connected successfully';
         mysqli_close($con);
      ?>

推荐阅读