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!

Related posts:

  1. Install MySQL5 on Mac OSX With Darwin Port Before installing MySQL5, please be sure you have Darwin Port...
  2. How to Change MySQL Data Directory in Linux Centos By default Linux CentOS or other Linux Distro installation, MySQL...
  3. Reset MySQL Root Password Very often, once we didn’t log on to MySQL database...
  4. MySQL 5 Server Cannot Start on Apple Mac Leopard There were some problem during configuring MySQL5 Server on Leopard...
  5. Install MySQL5 Server on Apple Mac Leopard with MacPorts Previously I wrote a post on “installing postgresql 8.2 on...
  6. postgresql82-server compile error on Apple Leopard with Macports 1.5 I wasn’t able to compile postgresql82-server on my machine, it’s...
  7. TextMate: Creating New Project in Shell Instantly Been using TextMate recently, really loving it like hell. There...
  8. You Must Restart Your MacBook Now Apple Macbook Restart Error Message Got this error message from...
  9. MySQL Quick Installation on FreeBSD Quick installation of MySQL Database on FreeBSD Server. Make sure...
  10. OS X Lion Macports OS X Lion Macports, Can I upgrade from Snow Leopard?...

Tags: , ,

Leave a Reply