2013-06-25 70 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和接受許可協議。更新下載了一個新的版本,我無法編譯任何東西,直到新的協議被手動接受。