首页 > 解决方案 > mysqli::real_connect(): 数据提前结束 (mysqlnd_wireprotocol.c:381),GREET 数据包比预期短 4 个字节

问题描述

我正在使用 wamp 服务器运行 php 和 mysql。

PHP 版本:7.0.33
MySql 版本:8.0.21
远程数据库服务器中的 MySql 版本:服务器版本:8.0.21 MySQL 社区服务器 - GPL

当我尝试使用 PHP mysqli 连接到 MySQL 时,出现以下错误。

Warning: mysqli::real_connect(): Premature end of data (mysqlnd_wireprotocol.c:370) in C:\wamp64\www\mysql_ssh\mysql_test.php on line 17
Warning: mysqli::real_connect(): GREET packet 4 bytes shorter than expected in C:\wamp64\www\mysql_ssh\mysql_test.php on line 17
Warning: mysqli::real_connect(): Error while reading greeting packet. PID=29292 in C:\wamp64\www\mysql_ssh\mysql_test.php on line 17
Warning: mysqli::real_connect(): [2002] (trying to connect via tcp://x.x.x.x:33060) in C:\wamp64\www\mysql_ssh\mysql_test.php on line 17
Warning: mysqli::real_connect(): (HY000/2002): in C:\wamp64\www\mysql_ssh\mysql_test.php on line 17

这是我的代码:

$ctx = mysqli_init();

$ctx->ssl_set('/mysql/client-key.pem', '/mysql/client-cert.pem', '/mysql/ca.pem', NULL, NULL);
$conn = $ctx->real_connect ($servername, $username, $password, $dbname, 33060, null);
if (!$conn) {
    die ('Connect error (' . $ctx->connect_errno . '): ' . $ctx->connect_error . "\n");
}

第 17 行代码:

$conn = $ctx->real_connect ($servername, $username, $password, $dbname, 33060, null);

标签: phpmysqlmysqli

解决方案


推荐阅读