无法使用本地网络连接上的工作台访问mysql服务器


Not able to access mysql server using workbench on local network connection

当我使用本地网络连接连接到网络时,我无法建立到服务器的连接。它返回以下错误:

Warning: mysqli::mysqli(): (HY000/2002): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. in C:'xxxx'htdocs'xxxx.xxxx'class'class.mysql.php on line 11
Connect Error (2002) A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. 
Warning: mysqli::close(): Couldn't fetch mysql in C:'xxxx'htdocs'xxxx.xxxx'class'class.mysql.php on line 59

现在,当我通过手机tether时,连接到服务器没有问题。

我对网络的了解非常无知,所以如果这是显而易见的,请原谅我,但是什么问题导致我无法连接到服务器?

我已经找到了我遇到的问题的答案。我在下面记录,以防对其他人有帮助。

=========================

我最近在读杨的《;建立自己的数据驱动网站"

某些软件包和操作系统之间似乎不兼容。特别是,当使用Apache在Windows Vista上运行时,尝试连接到MySQL时,这会影响PHP 5.3。这并不是一个真正的错误,而是在从IPv4到IPv6的过渡过程中,不同元素之间的差异。

基本上,当PHP尝试连接到数据库时,它会超时,因为它不识别localhost,只识别127.0.0.1,并产生以下错误消息:

=========================

警告:mysqli_connect()[function.mysqli connect]:[2002]连接尝试失败,因为被连接方没有(尝试通过tcp://localhost:3306)在第2行上的C:''Program Files''Apache Software Foundation''Apache2.2''htdocs''phpmysql-4''chapter4''connect''index.php中

警告:mysqli_connect()[function.mysqli connect]:(HY000/2002):由于连接方在一段时间后没有正确响应,连接尝试失败,或者由于连接的主机没有响应,建立的连接失败。在第2行上的C:''Program Files''Apache Software Foundation''Apache2.2''htdocs''phpmysql-4''chapter4''connect''index.php中

致命错误:第2行上的C:''Program Files''Apache Software Foundation''Apache2.2''htdocs''phpmysql-4''chapter4''connect''index.php中超过了30秒的最长执行时间

=========================

这个问题有两种可能的解决方案:

=========================

  1. 替换";localhost";用";127.0.0.1";在您希望连接到MySQL数据库的所有PHP文件中

  2. 定位";主机";文件。它通常位于这样的位置:

C: ''Windows''System32''drivers''etc''hosts

打开它,并注释掉阻止localhost";映射";正确地换句话说,改变

::1 localhost

::1 localhost

事实上,这个解决方案之前曾在SitePoint论坛上介绍过,但没有对细节进行全面解释。

http://www.sitepoint.com/forums/showthread.php?t=637612

=========================

PHP论坛上的以下链接详细描述了这个问题:

http://bugs.php.net/bug.php?id=45150

请注意,据我所知,Windows XP没有这个问题,因为它只配置为IPv4。Vista遇到了一个问题,因为它的设计是同时处理这两个问题,就像Windows7一样。

此外,我应该提到的是,不建议将PHP 5.2与前面提到的书一起使用,因为该版本中有一个错误——一个名副其实的错误——会导致Apache在尝试打开";删除笑话";文件