Mysql No connection could be made because the targ

2019-01-09 08:07发布

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

8条回答
疯言疯语
2楼-- · 2019-01-09 08:26

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楼-- · 2019-01-09 08:28

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

查看更多
forever°为你锁心
4楼-- · 2019-01-09 08:28

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.

查看更多
再贱就再见
5楼-- · 2019-01-09 08:28

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

查看更多
太酷不给撩
6楼-- · 2019-01-09 08:31

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
查看更多
疯言疯语
7楼-- · 2019-01-09 08:50

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!

查看更多
登录 后发表回答