php Mysql 无法建立连接,因为目标机器主动拒绝它

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22736396/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 16:13:18  来源:igfitidea点击:

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

phpmysqldatabasemysqlidatabase-connection

提问by BishoyM

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 .

我正在使用 php 进行开发,我需要连接到远程数据库,让我的所有团队都可以处理它。

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

localhost 运行良好,但是当我尝试切换时,它给了我这个错误

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 :

这是我想连接到 .nf.biz 数据库的代码:

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

采纳答案by BishoyM

Well this might be late but for future visitors,

好吧,这可能会晚,但对于未来的访客,

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

我当时发现biz.nf拒绝从外部来源连接到它的数据库,这意味着只有托管在biz.nf上的网络应用程序才能访问他们的数据库,除非你会被拒绝。

回答by Xavier Rubio Jansana

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

您的 MySQL 服务器仅接受 *nix 套接字上的连接(如果您运行的是 Ubuntu,则为 /var/run/mysqld/mysqld.sock)或仅适用于 localhost。

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

您必须编辑 my.cnf(在 Ubuntu 上再次位于 /etc/mysql/my.cnf)并更改以下内容:

bind-address = 0.0.0.0

bind-address = 0.0.0.0

And comment out the following

并注释掉以下内容

#skip-networking

#skip-networking

Finally restart MySQL.

最后重启MySQL。

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

请注意,如果您的 MySQL 机器可以从公共 Internet 访问,则将接受来自所有人的连接!

回答by Tomas Kubes

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.

当您在 c:\Windows\System32\Drivers\etc\hosts 中有一些 localhost 的别名时,MySQL 服务器中存在一个错误,MySQL 服务器无法接受到 localhost 的连接。

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

删除别名,MySQL 服务器将开始接受与 localhost 的连接。

回答by user2839515

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

我解决了在绑定地址中添加端口的问题:127.0.0.1:3388

回答by Randy Alien

I do nothave the #skip-networkingoption.

具备#跳过网络选项。

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

我通过散列绑定地址行来解决它(请参阅下面的第 3 行)。

# 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

回答by rkkp1023

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.
  1. 按 CTRL+R,然后键入 service.msc。一个窗口打开。
  2. 检查 MYSQL56 或 MYSQL57,单击它。
  3. 现在在窗口的左下角。点击展开。
  4. 再次刷新窗口,然后您可以看到启动服务选项。
  5. 单击它并解决错误。

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

这对我有用。希望你的错误也得到解决。给我发邮件:[email protected]

回答by Rodrigo Lugod

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

在 Windows 10 上使用 Wamp (php7) ......它当前正在工作,然后突然显示该错误。我重新启动了我的笔记本电脑,错误消失了......

回答by user2694130

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

我通过将 my.cnf 中的绑定地址设置为服务器的公共IP 地址来解决此问题:

# 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

回答by Suraj

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

您必须为当前活动的 mysql 服务器启动服务,就像我的 mysql80 一样,因此以下步骤可能会有所帮助:

start> cmd>run as administrator> sc start mysql80

回答by Badger_X

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

您的 MySQL 服务器仅接受 *nix 套接字上的连接(/var/run/mysqld/mysqld.sock如果您运行的是 Ubuntu)或仅用于 localhost。

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

您必须编辑您的my.cnf(在 Ubuntu 上再次位于/etc/mysql/my.cnf)并更改以下内容:

bind-address = 0.0.0.0

And comment out the following

并注释掉以下内容

#skip-networking

Finally restart MySQL.

最后重启MySQL。

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

请注意,如果您的 MySQL 机器可以从公共 Internet 访问,则将接受来自所有人的连接!

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

Worked perfect!

工作完美!