安装了 MacPorts PHP,现在无法与 MySQL 连接 - Mac OS X
我的 PHP 标准版本与 Mac OS X 捆绑在一起工作得很好,但我想升级到新版本,所以我使用了 MacPorts,一切顺利。然后我编辑了 .conf
文件并进行了检查,现在我的 PHP 版本已更新到最新版本。
然而,在运行我正在处理的 PHP 项目时,现在似乎我无法与 MySQL 进行交互,MySQL 正在使用与 Mac OS X 捆绑在一起的标准 PHP 安装(注意:我最初是从他们的安装程序安装 MySQL 的)主页)。
我的问题是:有没有办法让 MacPort PHP 与我旧的 MySQL 安装一起工作?
I had the standard version of PHP which comes bundled with Mac OS X working perfectly, but I wanted to upgrade to the new version so I used MacPorts, and all went well. I then edited my .conf
file and checked and now my version of PHP is updated to the latest version.
However, upon running a PHP project I'm working on, it now seems I am unable to interface with MySQL which was working with the standard PHP install which came bundled with Mac OS X (note: I originally installed MySQL from their installer from their homepage).
My question is this: Is there a way to get MacPort PHP to work with my old MySQL installation?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您是否从 MacPorts 安装了
php5-mysql
软件包?MacPorts 中 PHP 的默认安装相对较少,但有很多可用的附加模块。
Have you installed the
php5-mysql
package from MacPorts?The default installation of PHP in MacPorts is relatively minimal, but there are lots of add-on modules available.
正如 Alnitak 在评论中指出的,MacPorts 1.9.2 没有“mysql”变体。
不过,有一种方法可以解决这个问题。
php5-mysql 端口有一个 +mysql5 变体,但有一个更好的方法来解决问题。
这是一篇很棒的博客文章 http://top-frog。 com/2009/08/26/macports-php5-mysql-mysqlnd/
它只声明了与 php5-mysql 安装后脚本相同的短语:
要将 mysqlnd 与本地 MySQL 服务器一起使用,请编辑 /opt/local/etc/php5/php.ini 并设置 mysql.default_socket、mysqli。 default_socket 和 pdo_mysql.default_socket 到 /opt/local/var/run/mysql5/mysqld.sock
因此,如果您使用 MacOS X Server 本机 MySQL 服务器,则可以通过运行 ps ax 轻松获得该套接字| grep mysql 。对我来说是
/var/mysql/mysql.sock
。当然,您可以随时更改
/etc/my.cnf
中的套接字As noted by Alnitak in the comments, MacPorts 1.9.2 does not have a "mysql" variant.
There is a way to work around it, nevertheless.
The php5-mysql port has a +mysql5 variant, but there is an even better way to solve to problem.
This is a great blog post http://top-frog.com/2009/08/26/macports-php5-mysql-mysqlnd/
which only states the same phrase that the php5-mysql post-install script does:
To use mysqlnd with a local MySQL server, edit /opt/local/etc/php5/php.ini and set mysql.default_socket, mysqli.default_socket and pdo_mysql.default_socket to /opt/local/var/run/mysql5/mysqld.sock
So if you're using MacOS X Server native MySQL server that socket would be easy to get by running
ps ax | grep mysql
. For me it was/var/mysql/mysql.sock
.And you could of course always change the socket in
/etc/my.cnf
在疯狂的时刻我想出了办法。
使用 MacPorts 删除 PHP,然后重新安装,但这次在安装中添加了 +mysql。
完成后,也使用 MacPorts 安装 php5-mysql。然后就成功了!
In a moment of madness I worked it out.
Removed PHP from existence using MacPorts then reinstalled but this time added +mysql to the install.
Once this was done installed php5-mysql using MacPorts also. Then it worked!
我在安装 mysql 和 php5 时也遇到了同样的问题。幸运的是,我能够按照弗拉德的建议解决这个问题;以一种稍微不同的方式。请注意,端口 php5-mysql 不是必需的
尝试
/usr/bin/php -i|grep mysql|grep socket
这会导致Note that php is pointing to false place;它应该是
/opt/local/var/run/mysql5/mysqld.sock
解决方案:创建一个符号链接到正确的路径
I also went to same problem with mysql and php5 installed. Luckily I am able to fix this by following Vlads advice; in a little different way. Note that port php5-mysql is NOT REQUIRED
Try
/usr/bin/php -i|grep mysql|grep socket
which results inNote that php is pointing to wrong place; it should be
/opt/local/var/run/mysql5/mysqld.sock
Solution:Create a symlink to correct path