2010-12-09 72 views
4

在OSX當我嘗試使用以下命令:如何設置默認端口上的MySQL的Mac

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

我收到以下錯誤

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('[email protected]', NULL) 
#4 /Library/WebServer/sites/testweb/library/Zend/Db/Select.php(1000): Zend_Db_Adapter_Abstract->quoteInto('email = ?', '[email protected]', NULL) 
#5 /Library/WebServer/sites/testweb/library/Zen in /Library/WebServer/sites/testweb/library/Zend/Db/Adapter/Pdo/Abstract.php on line 144 

如果我添加:3306然後它工作

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

但是,然後Windows機器有這樣的連接問題。

有沒有辦法讓OSX只連接localhost的mysql默認端口?

+0

看看這個鏈接:http://www.comentum.com/mysql-administration.html – opHASnoNAME 2010-12-09 14:33:55

回答

11

要使用「本地主機」作爲一個IP,而不必試圖連接到插座UNIX系統,只需提供IP地址,而不是「localhost」的 - 127.0.0.1

resources.db.params.host = 127.0.0.1 

指定端口,你應該在必要時使用你的資源配置單獨的線:

resources.db.params.port = 3306 
+0

+1,因爲我有Linux的確切問題,這是我的解決方案。如果rschmitty會讓我們知道這是否適用於他的Mac,那將會很好。 – Fatmuemoo 2010-12-11 01:47:03

5

山獅與MAMP解決方案:

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