如何在 Mac OS X 上安装 MySQL gem

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4966795/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 18:43:35  来源:igfitidea点击:

How to install MySQL gem on Mac OS X

mysqlrubyosx-leopard

提问by synapse

What do I need to install mysql gem on Mac OS X ? I'm getting error "failed to build native extensions".

在 Mac OS X 上安装 mysql gem 需要什么?我收到错误“无法构建本机扩展”。

回答by Krule

Install MySQL first, either by using binary or Homebrew.

首先安装 MySQL,使用 binary 或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

如果您在 OS X 上升级到 MySQL 5.6.12 版,mysql2 将无法编译。解决方案是按照此处所述降级 MySQL:https: //stackoverflow.com/a/17252887/45254



Edit2

编辑2

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

如果您不想安装 mysql(也许您使用 docker 来管理您的服务)但想使用 mysql2 gem,您可以改为安装mysql-connector-c(使用自制软件)。

回答by Theo

Some time back I wrote some instructions on my blogon how to do it in 10.6, but I think it's the same in 10.5.

前段时间我在我的博客上写了一些关于如何在 10.6 中执行此操作的说明,但我认为在 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 .pkginstaller 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).

但您需要找到 的真正价值/path/to/mysql_config。我的博客文章有一些提示,但有一件非常重要的事情:您必须安装带有标头的 MySQL。.pkgMySQL的官方安装程序没有 IIRC。最好的办法是用Homebrew安装 MySQL (在帖子中我使用了 MacPorts 安装中的示例,但那是因为 Homebrew 在我编写它时还不成熟)。

If you install MySQL with Homebrew mysql_configwill be located at /usr/local/bin/mysql_configand if you install it with MacPorts it will be at /opt/local/lib/mysql5/bin/mysql_config.

如果您使用 Homebrew 安装 MySQLmysql_config将位于 ,/usr/local/bin/mysql_config如果您使用 MacPorts 安装它,它将位于/opt/local/lib/mysql5/bin/mysql_config.

I concur with the other answer that suggest that you install the mysql2gem instead of mysql. I think the command above should work for mysql2too.

我同意另一个答案,建议您安装mysql2gem 而不是mysql. 我认为上面的命令也应该适用mysql2

回答by Saikrishna Rao

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

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

brew install mysql-connector-c

followed by

其次是

gem install mysql

回答by JB Hewitt

I'm running Mac OS X Lion with Homebrew.

我正在使用 Homebrew 运行 Mac OS X Lion。

The correct command to install a ruby gem is…

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

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

回答by avillagran

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

我使用的是 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

and

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

This works for me ;)

这对我有用;)

回答by codener

For me it did the most easy:

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

brew install mysql
gem install mysql

Brew is a package manager for Mac OS, a musthave. Using it to install mysql first brings everything that the gem command is missing.

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

回答by Maciel Bombonato

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

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

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

回答by Alexandre Quintela

I install MySQL with DWG mysql_config will be located at /usr/local/mysql/bin/mysql_config

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

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

回答by tirdadc

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

我用 Homebrew 安装了 MySQL,我不得不使用它来最终升级 gem:

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

回答by tessie

I came across this issue while setting up MySQL gem on MacOs Mojave .This worked for me

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

1 Ensure Xcode command line tools are installed. xcode-select --install

1 确保安装了 Xcode 命令行工具。 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
  1. 对我来说,构建仍然失败,缺少一些头文件,您必须安装 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

此链接指向正确的方向。升级到 Mojave 后无法在 Mac 上编译 C 程序