mysqli_connect():(HY000/2002):无法建立连接,因为目标机器主动拒绝了它 [英] mysqli_connect(): (HY000/2002): No connection could be made because the target machine actively refused it

查看:1910
本文介绍了mysqli_connect():(HY000/2002):无法建立连接,因为目标机器主动拒绝了它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道有很多这样的问题,但是我没有找到任何解决方案.

I know there are many questions like this, but i didn't find any solution in it.

我尝试过的事情:-

  • 检查过的防火墙

  • checked firewall

重新启动我的PC和Apache服务器

restarted my PC and Apache server

重新启动MYSQL

检查了我的代码

尝试了我在互联网上发现并发现的所有内容

Tried everything i know and found on internet

这是我的代码:-

<?php

$dbhost = 'localhost:3360';
$dbuser = 'root';
$dbpass = '';
$db     = 'test_db13';


$conn  = mysqli_connect($dbhost,$dbuser,'',$db);

if(! $conn){
  die('Could not connect connect: ') ;
}

echo 'Successfully Connected';


$sql = 'Connected Successfully';
  $retvalue = mysqli_query($sql);

  if(! $retvalue){
    die('Cannot connect to SQL: ');
  }

echo 'DataBase test_db13 has successfully created';

mysqli_close($conn);

 ?>

我确实设置了密码,但是它仍然向我显示错误.

I did set the password, but it still is showing me the error.

这是防火墙图片:-

Here's the firewall picture:-

最后XAMMP正在运行,这就是证明

lastly XAMMP is running here's the proof

推荐答案

如果您查看XAMPP控制面板,则清楚地表明MySQL服务器的端口为3306-您提供了3360. 3306是默认值,因此不需要指定.即使如此,mysqli_connect()的第五个参数是端口,应该在此指定它.

If you look at your XAMPP Control Panel, it's clearly stated that the port to the MySQL server is 3306 - you provided 3360. The 3306 is default, and thus doesn't need to be specified. Even so, the 5th parameter of mysqli_connect() is the port, which is where it should be specified.

您可以完全删除端口规范,因为您使用的是默认端口,将其更改为

You could just remove the port specification altogether, as you're using the default port, making it

$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$db     = 'test_db13';

参考

这篇关于mysqli_connect():(HY000/2002):无法建立连接,因为目标机器主动拒绝了它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆