4

On OSX when I try to use the following:

resources.db.adapter = "pdo_mysql"
resources.db.params.dbname = "myDb"
resources.db.params.host = "localhost"
resources.db.params.username = "root"
resources.db.params.password = ""

I get the following error

Warning: PDO::__construct(): [2002] No such file or directory (trying to connect via unix:///var/mysql/mysql.sock) in /Library/WebServer/sites/testweb/library/Zend/Db/Adapter/Pdo/Abstract.php on line 129

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [2002] No such file or directory' in /Library/WebServer/sites/testweb/library/Zend/Db/Adapter/Pdo/Abstract.php:129
Stack trace:
#0 /Library/WebServer/sites/testweb/library/Zend/Db/Adapter/Pdo/Abstract.php(129): PDO->__construct('mysql:dbname=gl...', 'myDb', '', Array)
#1 /Library/WebServer/sites/testweb/library/Zend/Db/Adapter/Pdo/Mysql.php(96): Zend_Db_Adapter_Pdo_Abstract->_connect()
#2 /Library/WebServer/sites/testweb/library/Zend/Db/Adapter/Abstract.php(858): Zend_Db_Adapter_Pdo_Mysql->_connect()
#3 /Library/WebServer/sites/testweb/library/Zend/Db/Adapter/Abstract.php(928): Zend_Db_Adapter_Abstract->quote('asdf@asd...', NULL)
#4 /Library/WebServer/sites/testweb/library/Zend/Db/Select.php(1000): Zend_Db_Adapter_Abstract->quoteInto('email = ?', 'asdf@asd...', NULL)
#5 /Library/WebServer/sites/testweb/library/Zen in /Library/WebServer/sites/testweb/library/Zend/Db/Adapter/Pdo/Abstract.php on line 144

If I add :3306 then it works

resources.db.params.host = "localhost:3306"

However then windows machines have problems connecting like that.

Is there a way to have OSX connect on just localhost mysql default port?

chrisan
  • 4,152
  • 4
  • 28
  • 32

2 Answers2

11

To use 'localhost' as an ip instead of having unix systems attempting to connect to the socket, simply provide the ip-address instead of 'localhost' - 127.0.0.1

resources.db.params.host = 127.0.0.1

To specify the port, you should use the separate line in your resource configuration if necessary:

resources.db.params.port = 3306
Darryl E. Clarke
  • 7,537
  • 3
  • 26
  • 34
  • +1 as I had the exact problem with linux and this was the solutions for me. It would be nice if rschmitty would let us know if this worked for him on his mac. – Fatmuemoo Dec 11 '10 at 01:47
  • I did have the same issue on my macbook and I can confirm that using 127.0.0.1 instead of localhost is properly working now. – Bob Siefkes Jan 06 '13 at 21:10
5

Mountain Lion with MAMP solution:

sudo ln -f /Applications/MAMP/bin/php/php5.4.4/bin/php /usr/bin/php

Gonzalo.-
  • 12,512
  • 5
  • 50
  • 82
Joao Vanzuita
  • 53
  • 1
  • 4