2013-06-25 71 views
5

我在我的机器上安装mysql2 gem时遇到了问题。如何在Ruby 1.9.3下安装mysql2 gem?在2.0.0下工作

我有OS X 10.8与最新的Xcode和mySql通过Homebrew安装。所有使用最新RVM安装的红宝石。

我可以在安装红宝石精细mysql2 2.0.0-P195

[~]$ rvm use 2.0.0                [ruby-1.9.3-p429] 
Using /Users/aselder/.rvm/gems/ruby-2.0.0-p195 
[~]$ gem in mysql2                [ruby-2.0.0-p195] 
Fetching: mysql2-0.3.11.gem (100%) 
Building native extensions. This could take a while... 
Successfully installed mysql2-0.3.11 
1 gem installed 

下的Ruby 1.9.3和1.8.7,它无法找到的mysql.h文件

[~]$ rvm use 1.9.3                [ruby-1.9.3-p429] 
    Using /Users/aselder/.rvm/gems/ruby-1.9.3-p429 
    [~]$ gem in mysql2                [ruby-1.9.3-p429] 
    Fetching: mysql2-0.3.11.gem (100%) 
    Building native extensions. This could take a while... 
    ERROR: Error installing mysql2: 
     ERROR: Failed to build gem native extension. 

      /Users/aselder/.rvm/rubies/ruby-1.9.3-p429/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/aselder/.rvm/rubies/ruby-1.9.3-p429/bin/ruby 
     --with-mysql-config 
     --without-mysql-config 


    Gem files will remain installed in /Users/aselder/.rvm/gems/ruby-1.9.3-p429/gems/mysql2-0.3.11 for inspection. 
    Results logged to /Users/aselder/.rvm/gems/ruby-1.9.3-p429/gems/mysql2-0.3.11/ext/mysql2/gem_make.out 

我也尝试了各种命令行选项来获取gem来查找mysql安装:

eg 创业板安装mysql2 - --with-mysql的-配置=在/ usr /本地/选择/ MySQL的/斌/ mysql_config

+1

我有这个完全相同的问题,我一直没能弄清楚 – vanhowen

+0

我有完全相同的问题。我在一台全新的机器上(10.8)。 Ruby 2.0的工作没有问题,1.9.2和1.9.3抱怨缺少mysql.h。 – fflyer05

+0

你的MySQL版本是什么?我使用5.6.12也遇到了同样的问题。卸载它并安装5.6.10解决了这个问题。 –

回答

0

尝试使用自制软件和使用捆扎机的mysql2宝石安装mysql

brew update 
brew install mysql 

以下添加到您的Gemfile

gem "mysql2" 

运行:

bundle install 
+1

我已经完成了这项工作,仍然收到@aselder正在看到的错误 – vanhowen

+0

这似乎不适用于我。获取相同的错误。 – fflyer05

+0

好吧,试着按照这个人的回答http://stackoverflow.com/questions/11693360/mysql2-gem-cant-build-native-extensions希望这将解决你的问题球员:( –

0

我通过自制软件从5.6降级到的MySQL 5.5解决了这个问题。不能提供更详细的解释,但它修复了它。

+0

我会试试这个。谢谢。 –

+0

我currenlty有相同的问题,我正在使用5.5.31 – kyle

3

,我发现这个答案,它解决了我的问题:使用aptitude

在Ubuntu/Debian和其他发行版: Error installing mysql2: Failed to build gem native extension

报价

sudo apt-get install libmysql-ruby libmysqlclient-dev 

在Red Hat/CentOS的等使用yum的分布:

sudo yum install mysql-devel 

在Mac OS X与家酿:

brew install mysql 

我在Debian和运行上面的命令后,我跑:

gem install mysql2 

和它的工作NP。

1

我解决了用mysql服务器启动安装gem的问题!

brew install mysql 

mysql.server start 

bundle install 

在ruby-1.9.3-p125下。

希望这有助于

+0

这也适用于我@ Ruby 2.1.2 –

0

我有一个非常愚蠢的解决方案,这样的:我开了Xcode和接受许可协议。更新下载了一个新的版本,我无法编译任何东西,直到新的协议被手动接受。