MySQL Cannot Connect with PHP in OSX
I think some of you might have problem connecting to MySQL with PHP(mysql_connect) in Max OS X if you configured MySQL5 with Darwin Ports. Most probably you will get these error message;
Warning: mysql_connect() [function.mysql-connect]: Can’t connect to local MySQL server through socket ‘/opt/local/var/run/mysql5/mysqld.sock’ (13) in /Users/paulooicongjen/myproject/web/info.php on line 10
Could not connect: Can’t connect to local MySQL server through socket ‘/opt/local/var/run/mysql5/mysqld.sock’ (13)
The error message is caused by the folder mode created by MySQL installation by default. To solve this problem, change your folder mode to 755 and restart apache.
cd /opt/local/var/run
sudo chmod 755 mysql5
sudo apachectl restart
It should works now!