【问题标题】:Connection failed: SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client. Busy ports or source code problem?连接失败:SQLSTATE[HY000] [2054] 服务器请求客户端未知的身份验证方法。端口繁忙还是源代码问题?
【发布时间】:2021-11-12 20:15:03
【问题描述】:

我决定继续一个由于许多错误而放弃的旧项目。有了新的力量,我开始消除错误,但我到了卡住的地步。我很困难地发现我的问题来自与我的数据库的 PDO 连接,并且我的一半代码变得无法使用。我阅读了该主题并尝试了许多不同的方法来解决问题,但没有成功。对于初学者,我会说我使用 XAMPP,服务器版本:10.4.8-MariaDB,Apache / 2.4.41 (Win64) OpenSSL / 1.1.1c PHP / 7.3.1,phpMyAdmin 版本信息:5.1.1(最新) .因为很久没用XAMPP了,也安装了Workbench、Postgree等,只好改Apache和MySQL的端口。我在 phpMyAdmin 中为 root 帐户设置了密码,因为我读到这会有所帮助,但后来出现了更多问题,我在 phpMyAdmin 中使用了这个请求:

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

但是在这个查询中它给了我一个语法错误,为此我使用了一个成功的:

ALTER USER 'root'@'localhost' IDENTIFIED BY '...';

但问题依然存在。我还想插入一个事实,即我的项目中有 2 个连接字符串。一个没有问题,但是使用 PDO 连接字符串,我从 try catch 构造中得到了这个错误:

Connection failed: SQLSTATE [HY000] [2054] The server requested authentication method unknown to the client

我了解到问题可能是由于端口繁忙,但我决定在开始处理 XAMPP 文件之前咨询您。基本上我将端口更改为 3308,工作台更改为 3306,但是当我运行 XAMPP 时仍然收到一条错误消息:

Problem detected!
Port 3306 in use by "Unable to open process"!
MySQL WILL NOT start without the configured ports free!
You need to uninstall / disable / reconfigure the blocking application
or reconfigure MySQL and the Control Panel to listen on a different port

不过,我还是设法启动了 MySQL。

我决定写这篇文章是为了获得建议并可能帮助遇到同样问题的人,因为我看到有很多人遇到过这个问题。

【问题讨论】:

  • 另一个进程(程序)正在使用端口 3306,这就是消息所说的。要找出答案,请尝试netstat -a -b(另请参阅stackoverflow.com/questions/48198/…)
  • 基本上我通过 httpd.conf 和 my.ini 从 XAMPP 修复了这条消息。然后通过配置。但主要错误是:连接失败:SQLSTATE [HY000] [2054] 服务器请求客户端未知的身份验证方法@LarsStegelitz

标签: php mysql xampp


【解决方案1】:

感谢@iambpn -> https://github.com/laradock/laradock/issues/1392,我找到了解决问题的方法。我还安装了一个 mysql 服务器。我通过放置主机以与 2019 年 8 月 23 日的帖子相同的方式更改了连接字符串。我的解决方案如下所示:

$host = "127.0.0.1:3308";
$dbname = "inventory";
$user = "root";
$password = "------";

try {
    $dsn = 'mysql:host='.$ host.';dbname ='.$dbname;
    $connect = new PDO ($dsn,$user,$password);
    $connect->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
    return $connect;
} catch (PDOException $e) {
    echo 'Connection failed:'.$e->getMessage();
    exit;
}

但在此之前,如果安装了 SQL Server,则必须更改 XAMPP 端口!

【讨论】:

    猜你喜欢
    • 2019-05-05
    • 1970-01-01
    • 1970-01-01
    • 2016-12-15
    • 1970-01-01
    • 2015-05-02
    • 1970-01-01
    • 2019-07-18
    • 2018-10-10
    相关资源
    最近更新 更多