Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ERROR: SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it

Tags:

php

mysql

pdo

wamp

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 

this is the code of where the error is pointing

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

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.

like image 493
user3406220 Avatar asked Mar 20 '14 04:03

user3406220


People also ask

How do you fix Sqlstate hy000 2002 no connection could be made because the target machine actively refused it?

Check whether MySQL server is running at all. If that's the case, check whether you've entered the correct hostname and port number for your MySQL server (typically it's localhost:3306 or 127.0. 0.1:3306). in laravel 5, make sure you update your database on .

How do you fix no connection could be made because the target machine actively refused it?

You can try below solution: You might have a firewall rule in the way, or are trying to run it through a proxy without having the proxy up and running. The easiest way to check would be to disable your firewall or proxy and try again. Disable proxy at web.

Could not connect to server No connection could be made because the target machine actively refused it Connection failed Winscp?

“No connection could be made because the target machine actively refused it.” Generally, it happens that something is preventing a connection to the port or hostname. Either there is a firewall blocking the connection or the process that is hosting the service is not listening on that specific port.


1 Answers

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

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.

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.

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.

like image 109
RiggsFolly Avatar answered Sep 24 '22 11:09

RiggsFolly