7

サーバーに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を実行しません

そして私の宝石環境は

   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/

これは、最初のレールアプリを展開しようとして2日連続で運が悪いですが、はるかに簡単になります。

アップデート:

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
4

6 に答える 6

16

これはあなたに直接関係ないかもしれませんが、私はまったく同じ問題に直面しました。私の答えは、この問題で他の人を助けるかもしれないと思います:

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

それは私のために働いた。

于 2012-11-26T22:51:25.423 に答える
5

Mac を使用している場合は、Homebrewbrew install mysqlを使用して MySQL をインストールすると、後で gem をインストールできるようになります。

于 2013-01-13T18:14:11.713 に答える
3

コマンドは次のようになります。

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

オプション「with-mysql-config」は、構成ファイルではなく「mysql_config」ツールを参照します。

そして、mkmf.log ファイルの方が良いでしょう。

于 2012-04-11T09:16:41.380 に答える
0

sudo apt-get install libmysqlclient-dev システムは他の 2 つの lib をインストールします: mysql-common libmysqlclient16

于 2013-03-28T02:30:54.383 に答える
0

まず、次のコマンドを実行する必要があります。

sudo apt-get install libmysqlclient-dev

そして、これを実行できます:

gem install mysql2 

それは仕事であるべきです..

于 2013-03-09T10:26:08.920 に答える
0

「bundle exec rails console」はバンドラーの Gemfile に対して実行されますが、mysql2 を ruby​​gems でインストールしました。次を実行する必要があります。

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 を更新してください。

于 2014-01-06T18:20:37.460 に答える