安装了 MacPorts PHP,现在无法与 MySQL 连接 - Mac OS X

发布于 2024-10-24 08:15:32 字数 369 浏览 1 评论 0原文

我的 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 技术交流群。

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

发布评论

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

评论(4

冰雪梦之恋 2024-10-31 08:15:32

您是否从 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.

善良天后 2024-10-31 08:15:32

正如 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

征﹌骨岁月お 2024-10-31 08:15:32

在疯狂的时刻我想出了办法。

使用 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!

沩ん囻菔务 2024-10-31 08:15:32

我在安装 mysql 和 php5 时也遇到了同样的问题。幸运的是,我能够按照弗拉德的建议解决这个问题;以一种稍微不同的方式。请注意,端口 php5-mysql 不是必需的

尝试 /usr/bin/php -i|grep mysql|grep socket 这会导致

mysql.default_socket => /var/mysql/mysql.sock => /var/mysql/mysql.sock
mysqli.default_socket => /var/mysql/mysql.sock => /var/mysql/mysql.sock
pdo_mysql.default_socket => /var/mysql/mysql.sock => /var/mysql/mysql.sock

Note that php is pointing to false place;它应该是 /opt/local/var/run/mysql5/mysqld.sock

解决方案:创建一个符号链接到正确的路径

sudo mkdir /var/mysql
sudo ln -s   /opt/local/var/run/mysql5/mysqld.sock  /var/mysql/mysql.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 in

mysql.default_socket => /var/mysql/mysql.sock => /var/mysql/mysql.sock
mysqli.default_socket => /var/mysql/mysql.sock => /var/mysql/mysql.sock
pdo_mysql.default_socket => /var/mysql/mysql.sock => /var/mysql/mysql.sock

Note that php is pointing to wrong place; it should be /opt/local/var/run/mysql5/mysqld.sock

Solution:Create a symlink to correct path

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