2012-04-11 227 views
6

我想在服務器上安裝mysql2。所以我的第一個倒黴的線索是如下安裝mysql2時出錯

gem install mysql2 

輸出

Building native extensions. This could take a while... 
ERROR: Error installing mysql2: 
    ERROR: Failed to build gem native extension. 

/usr/bin/ruby1.8 extconf.rb 
checking for rb_thread_blocking_region()... no 
checking for rb_wait_for_single_fd()... no 
checking for mysql_query() in -lmysqlclient... no 
checking for main() in -lm... yes 
checking for mysql_query() in -lmysqlclient... no 
checking for main() in -lz... yes 
checking for mysql_query() in -lmysqlclient... no 
checking for main() in -lsocket... no 
checking for mysql_query() in -lmysqlclient... no 
checking for main() in -lnsl... yes 
checking for mysql_query() in -lmysqlclient... no 
checking for main() in -lmygcc... no 
checking for mysql_query() in -lmysqlclient... no 
*** 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 
    --without-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=/usr/bin/ruby1.8 
    --with-mysql-config 
    --without-mysql-config 
    --with-mysql-dir 
    --without-mysql-dir 
    --with-mysql-include 
    --without-mysql-include=${mysql-dir}/include 
    --with-mysql-lib 
    --without-mysql-lib=${mysql-dir}/lib 
    --with-mysqlclientlib 
    --without-mysqlclientlib 
    --with-mlib 
    --without-mlib 
    --with-mysqlclientlib 
    --without-mysqlclientlib 
    --with-zlib 
    --without-zlib 
    --with-mysqlclientlib 
    --without-mysqlclientlib 
    --with-socketlib 
    --without-socketlib 
    --with-mysqlclientlib 
    --without-mysqlclientlib 
    --with-nsllib 
    --without-nsllib 
    --with-mysqlclientlib 
    --without-mysqlclientlib 
    --with-mygcclib 
    --without-mygcclib 
    --with-mysqlclientlib 
    --without-mysqlclientlib 


Gem files will remain installed in /home/aaalsubaie/.gems/gems/mysql2-0.3.11 for inspection. 
Results logged to /home/aaalsubaie/.gems/gems/mysql2-0.3.11/ext/mysql2/gem_make.out 

這並不是故事的結尾

運行後

[ps89405]$ mysql --help | grep Default -A 1 
Default options are read from the following files in the given order: 
/etc/my.cnf /etc/mysql/my.cnf /usr/etc/my.cnf ~/.my.cnf 

我試圖

gem install mysql2 -- --with-mysql-config=~/.my.cnf --ruby=/usr/bin/ruby1.8 

gem install mysql2 -- --with-mysql-config=/usr/etc/my.cnf --ruby=/usr/bin/ruby1.8 

gem install mysql2 -- --with-mysql-config=/etc/my.cnf --ruby=/usr/bin/ruby1.8 

沒有運氣同樣的錯誤。

我不跑RVM

和我的寶石ENV是

RubyGems Environment: 
    - RUBYGEMS VERSION: 1.3.7 
    - RUBY VERSION: 1.8.7 (2010-08-16 patchlevel 302) [x86_64-linux] 
    - INSTALLATION DIRECTORY: /home/aaalsubaie/.gems/ 
    - RUBY EXECUTABLE: /usr/bin/ruby1.8 
    - EXECUTABLE DIRECTORY: /home/aaalsubaie/.gems/bin 
    - RUBYGEMS PLATFORMS: 
    - ruby 
    - x86_64-linux 
    - GEM PATHS: 
    - /home/aaalsubaie/.gems/ 
    - /usr/lib/ruby/gems/1.8 
    - GEM CONFIGURATION: 
    - :update_sources => true 
    - :verbose => true 
    - :benchmark => false 
    - :backtrace => false 
    - :bulk_threshold => 1000 
    - REMOTE SOURCES: 
    - http://rubygems.org/ 

這是我上排第二天嘗試沒有運氣我部署我的第一個Rails應用程序,雖然它會容易得多。

更新:

現在命令工作,mysql2寶石感謝醃好

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

安裝我現在有新的問題與mysql2寶石 當我運行

bundle exec rails console 

/home/aaalsubaie/ajhezaty.com/releases/20120411095320/vendor/bundle/ruby/1.8/gems/mysql2-0.3.11/lib/mysql2.rb:9:in `require': no such file to load -- mysql2/mysql2 (LoadError) 
from /home/aaalsubaie/ajhezaty.com/releases/20120411095320/vendor/bundle/ruby/1.8/gems/mysql2-0.3.11/lib/mysql2.rb:9 
from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.7/lib/bundler/runtime.rb:64:in `require' 
from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.7/lib/bundler/runtime.rb:64:in `require' 
from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.7/lib/bundler/runtime.rb:62:in `each' 
from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.7/lib/bundler/runtime.rb:62:in `require' 
from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.7/lib/bundler/runtime.rb:51:in `each' 
from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.7/lib/bundler/runtime.rb:51:in `require' 
from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.7/lib/bundler.rb:112:in `require' 
from /home/aaalsubaie/ajhezaty.com/releases/20120411095320/config/application.rb:7 
from /home/aaalsubaie/ajhezaty.com/releases/20120411095320/vendor/bundle/ruby/1.8/gems/railties-3.2.1/lib/rails/commands.rb:39:in `require' 
from /home/aaalsubaie/ajhezaty.com/releases/20120411095320/vendor/bundle/ruby/1.8/gems/railties-3.2.1/lib/rails/commands.rb:39 
from script/rails:6:in `require' 
from script/rails:6 

回答

3

的命令應該是這樣的:

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

選項「具有MySQL的-配置」指的不是配置文件的「mysql_config」工具。

而你最好是mkmf.log文件。

+1

/usr/local/mysql/bin /在我的服務器中不存在!我也不理解你的最後一行。 – aaalsubaie 2012-04-11 09:30:01

+0

感謝它安裝開發庫後工作。我現在有新的問題可以閱讀我對上述問題的更新。 – aaalsubaie 2012-04-11 10:00:15

+0

又一個'捆綁安裝'? – Reactormonk 2012-04-11 10:07:41

14

這可能不是給你直接的關係,但我面對完全相同的問題,我想我的回答可以幫助其他有此問題:

sudo apt-get install libmysql-ruby 
sudo apt-get install libmysqlclient-dev 
sudo gem install mysql2 

爲我工作。

+0

謝謝,節省時間) – ajahongir 2013-01-16 05:25:05

+0

謝謝你節省我的時間:) – 2013-01-22 09:36:44

+0

+1。感謝這有助於... – 2013-02-15 15:43:16

4

如果你在Mac上,安裝MySQL自制brew install mysql,那應該讓你安裝gem後。

0

首先,你必須運行此命令:

sudo apt-get install libmysqlclient-dev 

然後你就可以運行這個命令:

gem install mysql2 

它應該是工作..

0

sudo易於得到安裝libmysqlclient-dev 系統會安裝其他兩個lib: mysql -common libmysqlclient16

0

「bundle exec rails console」針對捆綁器的Gemfile運行,但是您使用rubygems安裝了mysql2。你需要運行:

gem uninstall mysql2    # uninstall mysql2 from system 
bundle exec gem uninstall mysql2 # uninstall mysql2 from bundler 
bundle config build.mysql2 --with-mysql-config=/usr/bin/mysql_config # set build option for mysql2 gem 
bundle install     # reinstall mysql2 
bundle exec rails console   # start rails console using the rails exec installed via bundler 

額外注:如果您使用的乘客,您只需更新你的Ruby版本,確保乘客重新安裝和更新你的httpd.conf,以便成功地啓動服務器。