mysql2 gem 无法在带有 Homebrew 的 OS X 上使用 MySQL 5.6.12 进行编译
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17238226/
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
mysql2 gem fails to compile with MySQL 5.6.12 on OS X with Homebrew
提问by pupeno
I updated all the packages I installed with Homebrew. MySQL got upgraded to 5.6.12 (from 5.5.27 or so):
我更新了我用 Homebrew 安装的所有软件包。MySQL 升级到 5.6.12(从 5.5.27 左右):
$ mysql --version
mysql Ver 14.14 Distrib 5.6.12, for osx10.8 (x86_64) using EditLine wrapper
and now the mysql2 gem doesn't compile anymore:
现在 mysql2 gem 不再编译:
$ gem install mysql2
Building native extensions. This could take a while...
ERROR: Error installing mysql2:
ERROR: Failed to build gem native extension.
/Users/pupeno/.rvm/rubies/ruby-1.9.3-p429-perf/bin/ruby extconf.rb
checking for rb_thread_blocking_region()... yes
checking for rb_wait_for_single_fd()... yes
checking for mysql.h... no
checking for mysql/mysql.h... no
-----
mysql.h is missing. please check your installation of mysql and try again.
-----
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.
Provided configuration options:
--with-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/Users/pupeno/.rvm/rubies/ruby-1.9.3-p429-perf/bin/ruby
--with-mysql-config
--without-mysql-config
The file mysql.h
is present in /usr/local/Cellar/mysql/5.6.12/include/mysql.h
. Any ideas what's going on?
该文件mysql.h
存在于/usr/local/Cellar/mysql/5.6.12/include/mysql.h
. 任何想法发生了什么?
The file mysql.h
doesn't appear in /usr/local
because the symlink seems to go deeper than it should:
该文件mysql.h
没有出现,/usr/local
因为符号链接似乎比它应该更深:
$ ls -la /usr/local/include/mysql
lrwxr-xr-x 1 pupeno admin 36 21 Jun 15:18 /usr/local/include/mysql@ -> ../Cellar/mysql/5.6.12/include/mysql
instead of
代替
/usr/local/Cellar/mysql/5.6.12/include
Having said that, I manually fixed the symlink and the compilation still failed. So I'm stuck.
话虽如此,我手动修复了符号链接,但编译仍然失败。所以我被困住了。
回答by iain
I had the same problem, I managed to fix it. I did a lot of things, and I don't know for sure what it was, but going to MySQL 5.6.10 seems to have worked.
我遇到了同样的问题,我设法解决了它。我做了很多事情,我不确定它是什么,但是使用 MySQL 5.6.10 似乎已经奏效了。
Uninstall MySQL 5.6.12:
卸载 MySQL 5.6.12:
brew unlink mysql
brew uninstall mysql
Go to the homebrew directory:
进入自制软件目录:
cd /usr/local
Go to version 5.6.10 (you can find a list of versions by running brew versions mysql
:
转到版本 5.6.10(您可以通过运行brew versions mysql
以下命令找到版本列表:
git checkout 48f7e86 Library/Formula/mysql.rb
Then install mysql again:
然后再次安装mysql:
brew install mysql
And now gem install mysql2
works for me.
现在gem install mysql2
对我有用。
I've also installed mysql from source (brew install mysql --build-from-source
), but that didn't solve it, but might be part of the solution.
我还从源代码 ( brew install mysql --build-from-source
)安装了 mysql ,但这并没有解决它,但可能是解决方案的一部分。
回答by Nedudi
just ;)
只是 ;)
gem install mysql2 -- --with-mysql-config=/usr/local/Cellar/mysql/5.6.10/bin/mysql_config
回答by croemmich
This also seemed to work for me. It forces the gem to compile against 5.6.10.
这似乎也对我有用。它强制 gem 针对 5.6.10 进行编译。
bundle config build.mysql2 --with-mysql-config=/usr/local/Cellar/mysql/5.6.10/bin/mysql_config
Related answer: https://stackoverflow.com/a/9360181
回答by jkrall
The top answer here is out-of-date... the brewers have fixed mysql:
这里的最佳答案已经过时了……酿酒商已经修复了 mysql:
brew update
brew upgrade mysql
gem install mysql2
This will update mysql to the latest version, which seems to work fine with the mysql2 gem on OSX.
这会将 mysql 更新到最新版本,这似乎与 OSX 上的 mysql2 gem 一起工作正常。
回答by Joshua Pinter
I had to specify the ldflags
and cppflags
for it to compile correctly, like this:
我必须指定ldflags
和cppflags
才能正确编译,如下所示:
gem install mysql2 -v '0.5.2' -- --with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include
回答by Matt Millsaps-Brewer
Much newer versions of MySQL are available, but for an older project install on Mac OS X Mojave, I still needed to run MySQL 5.6 and link against it in a Rails 5 app.
有很多新版本的 MySQL 可用,但对于在 Mac OS X Mojave 上安装的旧项目,我仍然需要运行 MySQL 5.6 并在 Rails 5 应用程序中链接它。
I configured bundler, then installed the bundle and was good to go.
我配置了 bundler,然后安装了 bundle,一切顺利。
$> brew install [email protected]
$> bundle config build.mysql2 --with-mysql-config=/usr/local/Cellar/mysql\@5.6/5.6.42/bin/mysql_config
$> bundle install
Note that you'll need to update the MySQL release version in the path.
请注意,您需要更新路径中的 MySQL 发行版本。
回答by jaysqrd
I would recommend this answer instead: mysql2 gem fails to compile with MySQL 5.6.12 on OS X with Homebrew
我会推荐这个答案:mysql2 gem failed to compile with MySQL 5.6.12 on OS X with Homebrew
The problem is with the compiler settings in Homebrew's version of MySql. Original answer found here: http://www.randomactsofsentience.com/2013/05/gem-install-mysql2-missing-mysqlh-on-os.html
问题在于 Homebrew 版本的 MySql 中的编译器设置。原始答案在这里找到:http: //www.randomactsofsentience.com/2013/05/gem-install-mysql2-missing-mysqlh-on-os.html