A connection attempt failed because the connected party did not (trying to connect via tcp://localho

在PHP连接MySQL时,出现如下错误:

Warning: mysql_connect() [function.mysql-connect]: [2002] A connection attempt failed because the connected party did not (trying to connect via tcp://localhost:3306) in E:\apache\www\mysql.php on line 20 Warning: mysql_connect() [function.mysql-connect]: 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 E:\apache\www\mysql.php on line 20
Fatal error: Maximum execution time of 60 seconds exceeded in E:\apache\www\mysql.php on line 20

解决方法有如下两个:

1、把C:\Windows\System32\drivers\etc\ hosts文件的

#127.0.0.1       localhost 

注释 # 去掉,就能连接成功了。这个解决方法也能使phpmyadmin 正常使用。

2、因为某些PHP版本不能把localhost转向到127.0.0.1,所以可以直接127.0.0.1也能成功。

你可能感兴趣的:(PHP,MySQL)