php 无法连接到“ipaddress”上的 MySQL 服务器 (110)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15576521/
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
Can't connect to MySQL server on 'ipaddress' (110)
提问by Al McKenzie
So I have a PHP file hosted on Namecheap server.
所以我在 Namecheap 服务器上托管了一个 PHP 文件。
$db=mysql_connect ("ipaddress", "user", "pass") or die ('I cannot connect to the database because: ' . mysql_error());
and it gives this error:
它给出了这个错误:
I cannot connect to the database because: Can't connect to MySQL server on 'ipaddress' (110)
我无法连接到数据库,因为:无法连接到“ipaddress”上的 MySQL 服务器 (110)
I CAN connect to this DB using mysql workbench outside of the network just fine.
我可以使用网络外的 mysql 工作台连接到这个数据库就好了。
回答by Mar Cejas
I have experienced this issue. What I did was use the internet address instead of your public IP/DNS.
我遇到过这个问题。我所做的是使用互联网地址而不是您的公共 IP/DNS。
Since, I'm using Linux I do ifconfigand you will see inet addr: xxx.xxx.xxx.xxxand use that IP as your host instead of the public IP/DNS. On Windows, Simply use your local IP address.
因为,我使用的是 Linux,所以ifconfig您将看到inet addr: xxx.xxx.xxx.xxx并使用该 IP 作为您的主机,而不是公共 IP/DNS。在 Windows 上,只需使用您的本地 IP 地址。
That's it!
就是这样!
回答by Daryl Gill
If you are using MySQL for your database solution (which seems odd due to the usage of IIS on a Windows Server operating system)
如果您使用 MySQL 作为您的数据库解决方案(由于在 Windows Server 操作系统上使用 IIS,这看起来很奇怪)
Try running (As Root):
尝试运行(以 Root 身份):
GRANT ALL ON Database.* TO Username@'IPAddress' IDENTIFIED BY 'PASSWORD';
GRANT ALL ON Database.* TO Username@'IPAddress' IDENTIFIED BY 'PASSWORD';
Where the second is the permissions that you are granting on, this is a place holder forall
第二个是您授予的权限,这是所有人的占位符
This will allow a connection from the IP you specify
这将允许来自您指定的 IP 的连接
also A problem is with connecting to your MySQL engine from inside your network, you will naturally connect from an internal IPV4 Address (192.168.0.x for example) this does not require portforwarding. BUT if you are using:
还有一个问题是从网络内部连接到 MySQL 引擎,您自然会从内部 IPV4 地址(例如 192.168.0.x)连接,这不需要端口转发。但是,如果您正在使用:
mysql_connect('WANIP', 'User', 'password');you will have to forward port 3306to your server. http://www.portforward.comfor assistance.
mysql_connect('WANIP', 'User', 'password');您必须将端口转发3306到您的服务器。http://www.portforward.com寻求帮助。
Edit:
编辑:
http://dev.mysql.com/doc/refman/5.0/en/can-not-connect-to-server.html
http://dev.mysql.com/doc/refman/5.0/en/can-not-connect-to-server.html
The manual for this subject, this may provide some assistance
这个主题的手册,这可能会提供一些帮助
If you are using Microsoft SQL Server check this link out:
如果您使用的是 Microsoft SQL Server,请查看此链接:
回答by Ajay Tribhuwan
I have faced this issue when installing opencart on my server. When i was using Windows server it requires IP address of website/domain. Now when shifted to linux hosting, linux hosting accpted as localhostAnd done. I could install opencart
我在我的服务器上安装 opencart 时遇到了这个问题。当我使用 Windows 服务器时,它需要网站/域的 IP 地址。现在,当转移到 linux 托管时,linux 托管被接受为localhost并完成了。我可以安装 opencart

