Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP/MYSQL connection problem on OS X Snow Leopard

Status
Not open for further replies.

peterv12

Technical User
Dec 31, 2008
108
US
I have a MYSQL database that I process using a PHP front-end. These run on a MacBook Pro using OS X Snow Leopard 10.6.4. This worked fine until a few days ago when I did a system update. At that point, I started getting the following message:
Code:
Warning: mysql_connect() [function.mysql-connect]: [2002] No such file or directory (trying to connect via unix:///var/mysql/mysql.sock) in /Users/peterv/Sites/INCLUDES/dbconnect.php  on line 3

Warning: mysql_connect() [function.mysql-connect]: No such file or directory in /Users/peterv/Sites/INCLUDES/dbconnect.php on line 3
Connect failed: No such file or directory

There is no //var/mysql/mysql.sock file on my system. The only mysql.sock file is in the /private/tmp directory. My php.ini file points to
Code:
/opt/local/etc ->
peterv@MBP17.local<524>$: nl php.ini
     1	mysql.default_socket = /tmp/mysql.sock
Can anyone help me out with this? I'm no php or mysql guru, so my only option right now seems to be reinstalling php or mysql.
Thanks....

 
connect using an ip address instead. don't use 'localhost', use the loopback address instead '127.0.0.1'

 
jpadie,
Thank you. This worked (as you probably knew that it would.) I am a little confused, however. I am a novice at this type of programming, but I have been using the 'localhost' literal for months, and it's worked just fine. The problem started a few days ago when Apple released an OS X update which changed a few things unexpectedly (like the php.ini file location). Can you explain to me why using the loopback address is preferable to using 'localhost'? (Aside from the fact that 'localhost' doesn't seem to work for me now.) If you know of some documentation on the web I can look at that'd be cool, I'll be searching too. Thanks again for getting my little utility back up and running!
 
in fact, you will find that you have not been using localhost in the way that you thought ... because localhost has a special meaning to mysql on *nix platforms.

from the mysql manual
On Unix, MySQL programs treat the host name localhost specially, in a way that is likely different from what you expect compared to other network-based programs. For connections to localhost, MySQL programs attempt to connect to the local server by using a Unix socket file.

so what happened is after your upgrade most probably your my.conf got overwritten or the default location for the socket has changed.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top