如何在 Mac OS X 上安装 MySQL gem

发布于 2024-10-16 19:59:50 字数 53 浏览 7 评论 0原文

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

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

发布评论

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

评论(10

善良天后 2024-10-23 19:59:50

首先使用二进制文件或 Homebrew 安装 MySQL。

然后:

gem install mysql2

或者:

gem install ruby-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:

gem install mysql2

Or:

gem install ruby-mysql

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).

枉心 2024-10-23 19:59:50

一段时间前,我写了 一些说明我的博客介绍了如何在 10.6 中做到这一点,但我认为在 10.5 中也是一样的。

我归结为这个命令:

ARCHFLAGS="-arch x86_64" gem install mysql -- \
  --with-mysql-config=/path/to/mysql_config

但是您需要找到 /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:

ARCHFLAGS="-arch x86_64" gem install mysql -- \
  --with-mysql-config=/path/to/mysql_config

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 of mysql. I think the command above should work for mysql2 too.

心清如水 2024-10-23 19:59:50

如果您已经在网络上的其他地方运行了 MySQL 服务器,并且希望仍然安装 gem 而无需安装 MySQL,请尝试以下

brew install mysql-connector-c

操作

gem install 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

brew install mysql-connector-c

followed by

gem install mysql
失去的东西太少 2024-10-23 19:59:50

我正在运行带有 Homebrew 的 Mac OS X Lion。

安装 ruby​​ gem 的正确命令是......

gem install mysql -- \ --with-mysql-config=/usr/local/bin/mysql_config 

I'm running Mac OS X Lion with Homebrew.

The correct command to install a ruby gem is…

gem install mysql -- \ --with-mysql-config=/usr/local/bin/mysql_config 
人事已非 2024-10-23 19:59:50

我使用的是 Mac OS X Mountain Lion,并通过 DMG 安装了 MySQL。

gem install do_mysql -- \ --with-mysql-dir=/usr/local/mysql --with-mysql-lib=/usr/local/mysql/lib --with-mysql-include=/usr/local/mysql/include

sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib

对我有用;)

I'm using Mac OS X Mountain Lion, and installed MySQL with DMG.

gem install do_mysql -- \ --with-mysql-dir=/usr/local/mysql --with-mysql-lib=/usr/local/mysql/lib --with-mysql-include=/usr/local/mysql/include

and

sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib

This works for me ;)

往日情怀 2024-10-23 19:59:50

对我来说,它做得最简单:

brew install mysql
gem install mysql

Brew 是 Mac OS 的包管理器,必须。首先使用它安装 mysql 会带来 gem 命令所缺少的一切。

For me it did the most easy:

brew install mysql
gem install mysql

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.

各空 2024-10-23 19:59:50

我用 Homebrew 安装了 MySQL,我必须使用它才能最终升级 gem:

gem install mysql2 -- --with-mysql-dir=/usr/local/opt/mysql/

I installed MySQL with Homebrew and I had to use this to finally be able to upgrade the gem:

gem install mysql2 -- --with-mysql-dir=/usr/local/opt/mysql/
旧时光的容颜 2024-10-23 19:59:50

我使用的是 Mac OS X 10.10 (Yosemite),对我来说使用以下命令:

gem install mysql2 -- \ --with-mysql-config=/usr/local/mysql/bin/mysql_config

I'm using Mac OS X 10.10 (Yosemite), and to me worked with the command bellow:

gem install mysql2 -- \ --with-mysql-config=/usr/local/mysql/bin/mysql_config
滥情稳全场 2024-10-23 19:59:50

我使用 DWG 安装 MySQL mysql_config 将位于 /usr/local/mysql/bin/mysql_config

gem install mysql -- \ --with 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

gem install mysql -- \ --with mysql-config=/usr/local/mysql/bin/mysql_config 
稚然 2024-10-23 19:59:50

我在 MacOs Mojave 上设置 MySQL gem 时遇到了这个问题。这对我有用

1 确保安装了 Xcode 命令行工具。
xcode-select --install

  1. 对我来说,构建仍然失败,缺少一些必须安装的头文件
    打开 /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

  1. For me the build was still failing with some header files missing which you have to 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

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