簡體   English   中英

安裝mysql2時出錯

[英]Error installing mysql2

我正在嘗試在服務器上安裝 mysql2。 所以我的第一個不幸的蹤跡如下

gem install mysql2

output

    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

我的寶石環境是

   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 應用程序,但運氣不佳,盡管這會容易得多。

更新:

感謝 Yanhao,現在該命令正在運行並安裝 mysql2 gem

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

當我運行時,我現在遇到了 mysql2 gem 的新問題

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

這可能與您沒有直接關系,但我遇到了完全相同的問題,我認為我的回答可能會幫助其他人解決這個問題:

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

那對我有用。

如果您使用的是 Mac,請使用 Homebrew brew install mysql ,之后您應該可以安裝 gem。

命令應該是這樣的:

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

選項“with-mysql-config”指的是“mysql_config”工具,而不是配置文件。

你最好有 mkmf.log 文件。

首先你必須運行這個命令:

sudo apt-get install libmysqlclient-dev

然后你可以運行這個:

gem install mysql2 

它應該是工作..

sudo apt-get install libmysqlclient-dev 系統會安裝另外兩個庫:mysql-common libmysqlclient16

“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 

附加注意事項:如果您使用的是 passenger 並且您剛剛更新了 Ruby 版本,請確保重新安裝 passenger 並更新您的 httpd.conf 以便成功啟動服務器。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM