如何在 Mac OS X 上安装 MySQL gem
在 Mac OS X 上安装 mysql gem 需要什么?我收到错误“无法构建本机扩展”。
What do I need to install mysql gem on Mac OS X ? I'm getting error "failed to build native extensions".
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
首先使用二进制文件或 Homebrew 安装 MySQL。
然后:
或者:
只需选择一个即可开始。
编辑
如果您在 OS X 上升级到 MySQL 版本 5.6.12,mysql2 将无法编译。解决方案是降级 MySQL,如下所述: https://stackoverflow.com/a/17252887/45254
Edit2
如果您不想安装 mysql(也许您使用 docker 来管理您的服务)但确实想使用 mysql2 gem,您可以安装 mysql-connector-c(使用自制软件)。
Install MySQL first, either by using binary or Homebrew.
Then:
Or:
Just pick one and you are good to go.
Edit
In case you upgraded to MySQL version 5.6.12 on OS X, mysql2 will fail to compile. Solution is to downgrade MySQL as described here: https://stackoverflow.com/a/17252887/45254
Edit2
In case you don't want to have mysql installed (maybe you use docker to manage your services) but do want to use mysql2 gem, you can instead install
mysql-connector-c
(using homebrew).一段时间前,我写了 一些说明我的博客介绍了如何在 10.6 中做到这一点,但我认为在 10.5 中也是一样的。
我归结为这个命令:
但是您需要找到
/path/to/mysql_config
的实际值。我的博客文章有一些提示,但有一件非常重要的事情:你必须安装带有标头的 MySQL。 MySQL 的官方.pkg
安装程序没有 IIRC。最好的办法是使用 Homebrew 安装 MySQL(在帖子中我使用了 MacPorts 安装中的示例,但那是因为我写的时候 Homebrew 还不成熟)。如果您使用 Homebrew 安装 MySQL,
mysql_config
将位于/usr/local/bin/mysql_config
,如果您使用 MacPorts 安装它,它将位于/opt/本地/lib/mysql5/bin/mysql_config
。我同意另一个答案,建议您安装
mysql2
gem 而不是mysql
。我认为上面的命令也应该适用于 mysql2。Some time back I wrote some instructions on my blog on how to do it in 10.6, but I think it's the same in 10.5.
I comes down to this command:
but you need to find the real value for
/path/to/mysql_config
. My blog post has a few tips, but there's one very important thing: you must have installed MySQL with headers. The official.pkg
installer from MySQL doesn't IIRC. The best thing to do is to install MySQL with Homebrew (in the post I use examples from a MacPorts install, but that's because Homebrew wasn't mature when I wrote it).If you install MySQL with Homebrew
mysql_config
will be located at/usr/local/bin/mysql_config
and if you install it with MacPorts it will be at/opt/local/lib/mysql5/bin/mysql_config
.I concur with the other answer that suggest that you install the
mysql2
gem instead ofmysql
. I think the command above should work formysql2
too.如果您已经在网络上的其他地方运行了 MySQL 服务器,并且希望仍然安装 gem 而无需安装 MySQL,请尝试以下
操作
if you already have MySQL server running elsewhere on the network and would like to still install the gem without having to install MySQL try the following
followed by
我正在运行带有 Homebrew 的 Mac OS X Lion。
安装 ruby gem 的正确命令是......
I'm running Mac OS X Lion with Homebrew.
The correct command to install a ruby gem is…
我使用的是 Mac OS X Mountain Lion,并通过 DMG 安装了 MySQL。
这
对我有用;)
I'm using Mac OS X Mountain Lion, and installed MySQL with DMG.
and
This works for me ;)
对我来说,它做得最简单:
Brew 是 Mac OS 的包管理器,必须。首先使用它安装 mysql 会带来 gem 命令所缺少的一切。
For me it did the most easy:
Brew is a package manager for Mac OS, a must have. Using it to install mysql first brings everything that the gem command is missing.
我用 Homebrew 安装了 MySQL,我必须使用它才能最终升级 gem:
I installed MySQL with Homebrew and I had to use this to finally be able to upgrade the gem:
我使用的是 Mac OS X 10.10 (Yosemite),对我来说使用以下命令:
I'm using Mac OS X 10.10 (Yosemite), and to me worked with the command bellow:
我使用 DWG 安装 MySQL mysql_config 将位于
/usr/local/mysql/bin/mysql_config
I install MySQL with DWG mysql_config will be located at
/usr/local/mysql/bin/mysql_config
我在 MacOs Mojave 上设置 MySQL gem 时遇到了这个问题。这对我有用
1 确保安装了 Xcode 命令行工具。
xcode-select --install
打开 /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg
此链接指向正确的方向。 无法编译 C 程序升级到 Mojave 后在 Mac 上
I came across this issue while setting up MySQL gem on MacOs Mojave .This worked for me
1 Ensure Xcode command line tools are installed.
xcode-select --install
open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg
This link pointed to right direction. Can't compile C program on a Mac after upgrade to Mojave