air air - 1 year ago 80
MySQL Question

MySQL working with 127.0.0.1 but not working with localhost?

I have a strange problem in php MySQL:

php connects with

127.0.0.1
but not with
localhost
.

How to solve this issue?

Answer Source

localhost must be defined in your hosts file, which it is by default on Windows and most OSs.

Check the following text file and see what's up:

C:\WINDOWS\system32\drivers\etc\hosts

Please note "hosts" is the file, no extension, it's not a folder. This file should be pretty much empty, if you see entries either your AV/spam blocker added a ton of entries that point to 127.0.0.1 or nasty malware has written garbage in there, despite, newer entries are below older ones. Localhost should be the first entry in that file.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download