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

查看:114
本文介绍了错误: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 ->应用程序 部分.里面的错误信息很好地确定了 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天全站免登陆