Mysql No connection could be made because the targ

2019-01-09 07:55发布

问题:

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

i want to connect to .nf.biz database

$db=mysqli_connect($host,$user,$password,$db_name,3306);

thanks erverone

回答1:

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!



回答2:

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.



回答3:

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


回答4:

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



回答5:

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


回答6:

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.



回答7:

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: rkkp1023@gmail.com



回答8:

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!