I am encountering a strange problem on my imac running OS X. For my frameworks and CMS configuration files if I use host: localhost (in db settings) an error is produced and the CMS/framework cannot connect to the database. However if I replace localhost to 127.0.0.1 everything seems to work fine. Since localhost is resolved to 127.0.0.1 I'd like to know what might be the problem with my php/mysql configurations that is resulting into this behavior.? I encountered this problem with Wordpress, Cake and CodeIgniter.
Asked
Active
Viewed 1.3k times
13
-
1Did you check `/etc/hosts` for a proper entry for `localhost`? – wallyk Mar 15 '12 at 06:45
-
There is difference, see http://stackoverflow.com/questions/3715925/localhost-vs-127-0-0-1 , http://dev.mysql.com/doc/refman/5.6/en/can-not-connect-to-server.html and google :) – biziclop Mar 15 '12 at 06:52
1 Answers
22
localhost
will cause the MySQL client to try a UNIX socket in a standard directory. If that doesn't exist or is somewhere else, you won't be able to connect. 127.0.0.1
always uses a TCP connection.
See the manual, C.5.2.2. Can't connect to [local] MySQL server.

deceze
- 510,633
- 85
- 743
- 889