Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I know there are many people already asked this , but this people mostly forgot password of blocked by firewall which I have none of this situations .

I am developing with php , and I need to connect to remote database to let all my team work on it .

localhost was just going fine , but when I tried to switch it gave me this error

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

and this is my code where I want to connect to .nf.biz database :

$db=mysqli_connect($host,$user,$password,$db_name,3306);
like image 909
BishoyM Avatar asked Mar 29 '14 20:03

BishoyM


People also ask

How do you fix no connection could be made because 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.

Can't connect to mysql server because the target machine actively refused it?

“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.


2 Answers

Your MySQL server is only accepting connections on *nix socket (/var/run/mysqld/mysqld.sock if you're running Ubuntu) or for localhost only.

You have to edit your my.cnf (on Ubuntu again is located in /etc/mysql/my.cnf) and change the following:

bind-address = 0.0.0.0

And comment out the following

#skip-networking

Finally restart MySQL.

Be careful with that, if your MySQL machine is accessible from public Internet will be accepting connections from everybody!

like image 91
Xavier Rubio Jansana Avatar answered Sep 23 '22 18:09

Xavier Rubio Jansana


I solved just adding the port in bind-address like that: 127.0.0.1:3388

like image 23
user2839515 Avatar answered Sep 23 '22 18:09

user2839515