cakephp on os x can’t connect to mysql

just a heads up… if you’re trying to use cakephp on os x with a mysql database, you’ll probably have problems connecting to the database server (by default).in my case, i created the mysql database (using the mysql command-line client), created a mysql user for the application (and gave it the appropriate permissions), configured cakephp’s database.php configuration file, and tried to access the default page. i was presented with the following error:

Warning: mysql_connect() [function.mysql-connect]: Can’t connect to local MySQL server through socket ‘/var/mysql/mysql.sock’ (2) in /Library/WebServer/Documents/application_name/cake/libs/model/dbo/dbo_mysql.php on line 100      

Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in /Library/WebServer/Documents/application_name/cake/libs/model/dbo/dbo_mysql.php on line 105 

the fix for this is pretty easy. i’ve seen recommendations to just make a symbolic link from /var/mysql/mysql.sock to /tmp/mysql.sock, but that’s not really a good idea. instead, open up /etc/php.ini in your text editor (as root), find the line that begins with “mysql.default_socket = ” and change the entire line so that it reads “mysql.default_socket = /tmp/mysql.sock” (make sure there’s not a semicolon at the beginning of the line). save the file, exit, and restart apache (“apachectl restart”) and you should be good to go.

note that if you don’t have an /etc/php.ini file, but you do have /etc/php.ini.default, simply copy the default file over (e.g. “cp /etc/php.ini.default /etc/php.ini”), then do the fix above.

share and enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Pownce
  • Reddit
  • StumbleUpon

related posts:
  • apple is killing linux on the desktop
  • my bookmarks
  • send email from postgresql
  • revisited: new linux server
  • dd-wrt

  • 4 comments ↓

    #1 Bob Kremmins on 03.26.08 at 5:25 am

    Thanks a lot for the help!

    Just what I needed!

    #2 jeremy on 05.03.08 at 8:11 pm

    excellent, glad i be of some help!

    #3 maca on 08.13.08 at 3:56 pm

    hey!!! perfect! works ok!

    sos un capo!

    my thanks… from argentina

    #4 Nicolas on 08.13.08 at 4:08 pm

    Thanks a lot :)

    Leave a Comment