php - PHP,MySQL 返回“连接失败:服务器请求客户端未知的身份验证方法”
问题描述
尝试连接到本地 Mysqli DB。
数据库连接:
<?php $con= new mysqli("localhost","Kobe24","Kobei987","Bkn_Data");
if ($con->connect_error) {
die("Connection failed: " . $con->connect_error);
}
返回这个:
Warning: mysqli::__construct(): (HY000/2054): The server requested authentication method unknown to the client in C:\Apache24\htdocs\poc\practice_project\database_connection.php on line 1
Connection failed: The server requested authentication method unknown to the client
任何反馈都会有所帮助。一直在研究这个问题,但没有明确的解决方案。
解决方案
你能按照下面的代码试试这个mysqli_connect()函数吗?还请确保数据库用户和密码正确,并且该用户具有连接数据库的权限
<?php
$dbhost = 'localhost:3306';
$dbuser = 'enter database user';
$dbpass = 'enter password';
$con = mysqli_connect($dbhost, $dbuser, $dbpass);
if(! $con ){
die('Could not connect: ' . mysqli_error());
}
echo 'Connected successfully';
mysqli_close($con);
?>
推荐阅读
- c++ - Can you `= delete` a templated function on a second declaration?
- html - HTML 的边距大于正文
- php - 在存档页面的帖子中查看所有 ACF 灵活内容
- mysql - 如何通过多对多关系从 SQL 提取中排除具有相关关键字的行
- mysql - 无法使用 spark-submit 连接 hive mysql Metastore
- r - 无法将日期因子转换为日期时间
- java - 在地图中将行转置或转换为列
- google-cloud-platform - GCP:列出每个资源的可授予角色
- prometheus - 追踪:如何使用分配来无限增加价值
- c# - 无法信任 ASP.NET Core 中的本地 HTTPS 证书