php - 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);
解决方案
推荐阅读
- python-3.x - 如何影响图形节点的位置以进行可视化?
- tensorflow - 如何在 Tensorflow 中使用 GPU 进行大矩阵分解
- git - “退出状态 128”试图从 golang 创建 git 分支
- pandas - 如何对多列中的数据进行分箱?
- swift - 有没有办法在 5 秒后传递一个变量?
- node.js - 解析服务器和 node.js 基础知识入门
- ios - 将位置信息从 uibutton 传递到地图视图页面并开始导航
- c# - GDI+System.Runtime.InteropServices.ExternalException HResult=0x80004005 Message=GDI+ 中发生一般错误
- python-3.x - 如何使用索引查找列表的中位数
- aws-lambda - 有没有办法在 ALB lambda 上返回 JSON?