如何在 Mac 上的 MySQL 上设置默认端口

发布于 2024-10-06 16:29:51 字数 1664 浏览 7 评论 0原文

在 OSX 上,当我尝试使用以下命令时:

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('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

如果我添加 :3306 则它可以工作

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

但是 Windows 机器会出现这样的连接问题。

有没有办法让 OSX 仅连接 localhost mysql 默认端口?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

能否归途做我良人 2024-10-13 16:29:51

要使用“localhost”作为 ip,而不是让 UNIX 系统尝试连接到套接字,只需提供 ip 地址而不是“localhost” - 127.0.0.1

resources.db.params.host = 127.0.0.1

要指定端口,您应该在资源配置中使用单独的行如有必要:

resources.db.params.port = 3306

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
最佳男配角 2024-10-13 16:29:51

Mountain Lion 使用 MAMP 解决方案:

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

Mountain Lion with MAMP solution:

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文