【问题标题】:Not able to make connection to mysql 8 in php无法在 php 中连接到 mysql 8
【发布时间】:2023-03-28 23:39:01
【问题描述】:

我正在尝试使用 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

【问题讨论】:

标签: php mysql


【解决方案1】:

我也遇到过类似的问题,发现可以通过Workbench运行下面的代码来改变mysql认证

ALTER USER root@localhost IDENTIFIED WITH mysql_native_password BY 'new-password-here'

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-22
    • 2023-03-11
    • 1970-01-01
    • 1970-01-01
    • 2015-03-01
    • 2016-11-29
    相关资源
    最近更新 更多