错误:SQLSTATE [HY000] [2002]无法建立连接,因为目标计算机主动拒绝了它 [英] ERROR: SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it

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

问题描述

在调试代码时突然发生错误. 关于与数据库的连接,它存在一系列错误.

An error suddenly occurred while I was debugging my code. It has this series of errors regarding the connection to database.

ERROR: SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it.
( ! ) Fatal error: Uncaught exception 'PDOException' with message ' in C:\wamp\www\web\main\users.php on line 15
( ! ) PDOException: SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it. in C:\wamp\www\web\main\users.php on line 15

这是错误所指向的代码

function __construct()
        {
            $this->con = new PDO("mysql:host=".$this->host.";dbname=".$this->db,$this->user,$this->pass);
        }

我不知道该怎么办,因为我通常不会遇到这样的问题,所以我对WAMP的研究并不多. 谢谢您的帮助.

I don't know what to do since I do not usually get problems like this so I haven't studied much about WAMP. Thank You for your help.

推荐答案

如果WAMP图标为橙色,则其中一项服务尚未启动.

If the WAMP icon is Orange then one of the services has not started.

在您的情况下,由于您收到指示没有服务器运行的消息,因此MySQL似乎尚未启动,因此正在侦听请求.

In your case it looks like MySQL has not started as you are getting the message that indicates there is no server running and therefore listening for requests.

查看mysql日志,如果没有告诉您Windows日志,请参见Windows -> Applications部分.其中的错误消息非常善于识别MySQL无法启动的原因.

Look at the mysql log and if that tells you nothing look at the Windows event log, in the Windows -> Applications section. Error messages in there are pretty good at identifying the cause of MySQL failing to start.

有时这是由WAMPServers MySQL从另一个安装中获取的my.ini文件引起的,通常在\ windows或\ windows \ system32文件夹中.搜索"my.ini"和"my.cnf",如果您在\ wamp ....文件夹结构之外的任何位置找到其中之一,则将其删除,或者至少将其重命名,以便找不到它.然后重新启动MySQL服务.

Sometimes this is caused by a my.ini file from another install being picked up by WAMPServers MySQL, normally in the \windows or \windows\system32 folders. Do a search for 'my.ini' and 'my.cnf' and if you find one of these anywhere outside of the \wamp.... folder structure then delete it, or at least rename it so it wont be found. Then restart the MySQL service.

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

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