BishoyM
BishoyM

Reputation: 641

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);

Upvotes: 14

Views: 67942

Answers (11)

VickyP
VickyP

Reputation: 21

Go to services enable the service named after the root user (under the category "Log On As" -> Network Service)

Upvotes: 1

Rodrigo Lugod
Rodrigo Lugod

Reputation: 1

Using Wamp (php7) on Windows 10... It is currently working then it suddenly displayed that error. I restarted my laptop and the error is gone...

Upvotes: 0

Suraj
Suraj

Reputation: 11

You have to start you service for the currently active mysql server, like mine was mysql80 so the following steps might help:

start> cmd>run as administrator> sc start mysql80

Upvotes: -1

rkkp1023
rkkp1023

Reputation: 9

This error occurs when the database is not responding.

I resolve this error by following steps:

  1. Press CTRL+R then type service.msc. A window opens.
  2. Check for MYSQL56 OR MYSQL57, click on that.
  3. NOW on the left bottom corner of the window. click on the expand.
  4. Again window refresh then u can see the start service option.
  5. click on that and the error resolve.

This works for me. hope your error is also resolved. mail me: [email protected]

Upvotes: 0

Tomas Kubes
Tomas Kubes

Reputation: 25128

Even if this is not your case, I will add the answer here, because the message for this bug is the same.

There is a bug in MySQL server when you have some alias for localhost in c:\Windows\System32\Drivers\etc\hosts, MySQL server is unable to accept connection to localhost.

Remove the alias and MySQL Server will start to accept connections to localhost.

Upvotes: 4

BishoyM
BishoyM

Reputation: 641

Well this might be late but for future visitors,

I found out back then that biz.nf refuses any connections to it's DB from outside source which means that only the web-apps hosted on biz.nf have the access to their DB other than that you will get rejected.

Upvotes: 1

user2694130
user2694130

Reputation: 1

I fixed this by setting the bind-address in my.cnf to the server's public IP address:

# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address            = SERVER_IP_ADDRESS

Upvotes: 0

user2839515
user2839515

Reputation: 29

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

Upvotes: 2

Badger_X
Badger_X

Reputation: 11

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!

sudo -s
sudo gedit /etc/mysql/my.cnf
bind-address = 0.0.0.0
#skip-networking
save
sudo service mysql restart

Worked perfect!

Upvotes: -2

Randy Alien
Randy Alien

Reputation: 21

I do not have the #skip-networking option.

I resolved it by hashing out the bind address line (See 3rd line below).

# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.**
#bind-address       = 127.0.0.1

Upvotes: 2

Xavier Rubio Jansana
Xavier Rubio Jansana

Reputation: 6583

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!

Upvotes: 16

Related Questions