This question already has answers here:
MySQL remote connection fails with “unknown authentication method”
                                
                                    (7个答案)
                                
                        
                        
                            php mysqli_connect: authentication method unknown to the client [caching_sha2_password]
                                
                                    (12个答案)
                                
                        
                                在8个月前关闭。
            
                    
我刚刚安装了xampp,并且正在phpMyAdmin上本地运行MySQL数据库。我正在尝试通过.php doc输出数据库的内容,但在尝试这样做时会收到两个警告:

警告:mysqli :: __ construct():服务器在第20行的C:\ xampp \ htdocs \ footfallTracker \ test.php中请求客户端[caching_sha2_password]未知的身份验证方法

警告:mysqli :: __ construct():(HY000 / 2054):服务器在第20行的C:\ xampp \ htdocs \ footfallTracker \ test.php中请求客户端未知的身份验证方法
连接失败:服务器请求客户端未知的身份验证方法

这是我正在使用的代码:

     <?php
$servername = "localhost";
$username = "root";
$password = "*2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19";
$dbname = "footfall_tracking";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

$sql = "SELECT ID, Location, Date FROM footstep_count";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        echo "ID: " . $row["ID"]. " - Location: " . $row["Location"]. " - Date: " . $row["Date"]. "<br>";
    }
} else {
    echo "0 results";
}
$conn->close();
?>

最佳答案

这段代码对我有帮助

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


你可以在这里检查它:D
The server requested authentication method unknown to the client (PHP)
THI

关于php - mysqli::__ construct():客户端未知的身份验证方法[caching_sha2_password] x ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/54362412/

10-09 00:55
查看更多