mysql_connect():由于目标机器主动拒绝连接,因此无法建立连接 [英] mysql_connect(): No connection could be made because the target machine actively refused it

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

问题描述

当我尝试运行PHP MySQL脚本时遇到此问题.当我尝试运行.php文件时,这就是我所得到的.

I have this problem when I am trying to run my PHP MySQL script. When I try to run my .php file this is what I get.

mysql_connect(): No connection could be made because the target machine actively refused it

这是dbconnect.php的代码:

This is code for dbconnect.php:

<?php
mysql_connect("localhost","root");
mysql_select_db("users");
?>

我以前尝试使用这种格式,但是我不知道这段代码似乎是什么问题.

I tried to use this format before but I don't know what seems to be the problem with this code.

谢谢.

推荐答案

您在连接中忘记了密码.

You forgot password in your connection.

尝试一下.

    mysql_connect("localhost","root" ,"password here");

在此处查看文档.

  • 您应该切换到MYSQLIPDO,因为您会发现MYSQL已被弃用.

  • You should switch to MYSQLI or PDO as you see that MYSQL is already deprecated.

根据mysql ver 5.0的此信息,初始Mysql密码为空.您应该检查您的版本.

The initial Mysql password is blank according to this info for mysql ver 5.0. you should check your version.

  mysql_connect("localhost","root" ,""); // will connect.

无法建立连接,因为目标计算机主动拒绝了连接

No connection could be made because the target machine actively refused it

这意味着您的代码中没有错误,但是您的防火墙阻止了您的连接,或者系统正在使用其他PORT进行监听.

means that no error in your code , but either you have firewall which blocks your connection or your sistem is listening in different PORT.

要做的事情:1-验证您的连接端口默认值为3306.

to do: 1-verify your connecting port default is 3306.

2-请尝试使用"127.0.0.1"而不是"localhost"进行连接,这可能是因为它监听了"127.0.0.1".

2-try connect with use "127.0.0.1" instead of "localhost" this maybe it listening on "127.0.0.1".

3-如果另一端正在侦听UDP,而不是TCP,这也可能出错.

3-It could also go wrong if the other end is listening on UDP, not TCP.

4-如果允许,请验证您的防火墙连接.

4- verify your firewall connection if its permitted.

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

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