mysql - 如何在 MySQL for Mac 上设置默认端口

标签 mysql zend-framework zend-db

在 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 默认端口?

最佳答案

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

resources.db.params.host = 127.0.0.1

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

resources.db.params.port = 3306

关于mysql - 如何在 MySQL for Mac 上设置默认端口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4399269/

相关文章:

php - Zend Model Mapper fetchAll() 忽略我的 WHERE 子句

php - 插入数组上的 zend db 引号(转义)将引号添加到字符串

php - 使用 PHP 将 CSV 导入 MySQL

mysql - apt-get update 更新mysql失败

MySQL 过程不识别表

zend-framework - Zend Form Validation::Does exist oposite validator to Identical?[如何检查与 'str' 不相同的输入]

php - 证书存储可以放在 application.ini 而不是 php.ini 中吗

php - 为特定的 ZF1 模块禁用 HTTPS

php - Zend Framework : Form: Should I use camelCase for form element names & DB tables, 与否?

mysql - 查找数据库中具有包含特定值的列的所有表名,MySQL