无法安装mysql2 gem。安装找不到mysql.h

时间:2012-11-08 22:38:36

标签: mysql ruby-on-rails-3 rubygems

我正在尝试安装mysql2:

sudo gem install mysql2 -v '0.2.7' -- --with-mysql-config=/usr/local/Cellar/mysql/5.5.25a/bin/mysql_config

我收到了这个错误:

ERROR:  Error installing mysql2:
    ERROR: Failed to build gem native extension.

       /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb --    with-mysql-config=/usr/local/Cellar/mysql/5.5.25a/bin/mysql_config
checking for rb_thread_blocking_region()... no
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.

我的mysql安装是通过brew,所以我的mysql.h文件位于:

/usr/local/Cellar/mysql/5.5.25a/bin/mysql_config

这就是为什么我有with-mysql-config标志

mysql_config文件在这里查找mysql.h文件:

$basedir/include/mysql/mysql.h

应该添加我从

更新我的gemfile

gem'mysql2

到gem'mysql2','0.2.7'

因为,我收到一些关于mysql2 0.3。*没有活动记录支持这一事实的弃用警告。因此要么必须将rails升级到3.1或降级mysql2。我选择了后者。

我应该编辑mysql_config还是我还能做些什么来解决这个问题?谢谢你的帮助。

2 个答案:

答案 0 :(得分:3)

我意识到这是一个古老的问题,但对于从谷歌来到这里的任何人,我发现这个解决方案对我有用:http://www.randomactsofsentience.com/2013/05/gem-install-mysql2-missing-mysqlh-on-os.html

简短版本是从第120行的-Wno-null-conversion -Wno-unused-private-field中删除编译器标志/usr/local/Cellar/mysql/5.6.12/bin/mysql_config(用你必须找到的文件替换mysql版本)。

我在OSX上使用自制软件mysql和rvm使用ruby 1.9.3。

答案 1 :(得分:2)

您应该安装mysql-dev包,这里有一些标题用于编译本机驱动程序。