I have a strange problem in php MySQL:
php connects with 127.0.0.1
but not with localhost
.
How to solve this issue?
normally means that there is no MySQL server running on the system or that you are using an incorrect Unix socket file name or TCP/IP port number when trying to connect to the server. You should also check that the TCP/IP port you are using has not been blocked by a firewall or port blocking service.
Testing your Local SQL ServerClick on the “New Connection” icon and leave everything default, except the “Connection Name,” here enter localhost . Double click on the new connection and enter the password you created during installation. Voila! Let's run a command to make sure everything is working.
What is the IP address of MySQL server? Hostname: The host name or IP address of the MySQL server. The host name "localhost" might resolve to "127.0. 0.1" or "::1" on your host, so note this when checking permissions.
If the PHP directive mysql. default_host is undefined (default), then the default value is 'localhost:3306'. In SQL safe mode, this parameter is ignored and value 'localhost:3306' is always used.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With