A connection attempt failed because the connected party did not properly respond

If you’re like me, using EasyPHP on Windows 7 for local development and have encountered this PHP/MySQL error:

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
C:\Path\To\Script.php on line 26

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
C:\Path\To\Script.php on line 26

Fatal error: Maximum execution time of 30 seconds exceeded in
C:\Path\To\Script.php on line 26

..then you’re in luck! Here’s a quick easy fix:

  1. Go to “C:\Windows\System32\drivers\etc“.
  2. Open “hosts” with Notepad program.
  3. Uncomment this line: “127.0.0.1 localhost” or add it if it’s not on the host entry.

That’s it! Save the changes you’ve made and refresh your browser.

Hope this helps!

* NOTE – Make sure you have a full access on “hosts” file.

  1. Right click on “hosts” file then click “Properties“.
  2. On “Security” tab click “Edit…” button.
  3. Select the user that you are currently using.
  4. Under “Permissions for Users” box, tick “Full control” on “Allow” column.
  5. And then click “OK” button to apply the changes.

10 thoughts on “A connection attempt failed because the connected party did not properly respond

  1. i have the same issue as well that the line is not commented. checking the file, it contains these following lines:

    127.0.0.1 local host
    ::1 local host

    what i did is change the “::1″ into “127.0.0.1″ and that fixed the problem.
    hope this fix helps somebody. ^_^

  2. Hi,

    You want to leave these lines uncommented as they are necessary for the proper working of your local network:
    127.0.0.1 localhost
    ::1 localhost

    MySQL has a bug. It is unable to deal with multiple addresses returned for a single name. Compounding this bug, it is also unable to deal with IPv6 addresses. So when MySQL receives first the IPv6 address for localhost, it times out eventually.

    The fix is to replace “localhost” with “127.0.0.1″ in your PHP script.

  3. This also affected me with Uniform Server.

    Ron – do you mean leave the lines in the hosts file commented out? Or uncommented?

  4. replacing the localhost with the ip worked for me…..thank you. I was pulling my hair out.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>