I have a strange problem in php MySQL:
php connects with 127.0.0.1
but not with localhost
.
How to solve this issue?
I have a strange problem in php MySQL:
php connects with 127.0.0.1
but not with localhost
.
How to solve this issue?
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.
Try:
IE-->Tools-->Options--> Connection --> LAN Settings Check Bypass Proxy for local addresses
Also have a look inside the mysql database which defines the user access privileges. You can define there from which source hosts a given user is allowed to connect. You can consult http://dev.mysql.com/doc/refman/5.1/en/connection-access.html for more details
Try ping localhost
in a command line, it may be resolving to ::1:
the IP6 equivalent to 127.0.0.1
To fix it, add (or uncomment) the line:
127.0.0.1 localhost
in C:\WINDOWS\system32\drivers\etc\hosts
I remember that being a longstanding and documented feature of Mysql on Windows. Something about the way local sockets work or something.
Is localhost resolving to the IPv6 address, as opposed to the IPv4, and MySQL is not listening on the v4 address?
The solution is make localhost resolve to the v4 address, OR make MySQL listen on the v6 address.
If MySQL connects to 127.0.0.1 it does so via TCP/IP whereas if it connects to localhost it does so via a socket.
Is PHP looking in the right place for mysql.sock? Make sure php.ini and my.conf have matching locations