我正在尝试使用 php 连接到 mysql 服务器,但出现以下错误
Connection failed: The server requested authentication method unknown to the client
mysql服务器版本为8.0.12,php版本为7.2.9。 我的代码连接到mysql服务器
<?php
$servername = "127.0.0.1";
$username = "root";
$password = "mypassword";
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>
这个问题之前有人问过here但解决方案对我不起作用,所以我再次问这个问题。 谢谢
编辑:我现在重新安装了 php,它为相同的代码提供了以下内容
This page isn’t working
127.0.0.1 is currently unable to handle this request.
HTTP ERROR 500
最佳答案
我遇到了类似的问题,发现你可以通过Workbench运行下面的代码来改变mysql的认证
ALTER USER root@localhost IDENTIFIED WITH mysql_native_password BY 'new-password-here'
关于php - 无法在 php 中连接到 mysql 8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52219271/