81

mysql2 gemをインストールしようとすると、明らかなエラーなしで失敗します。mysql2がインストールされるように、これを回避するために何をすべきか誰かが知っていますか?

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

/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb
checking for rb_thread_blocking_region()... 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... no
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=/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
    --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 /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6 for inspection.
Results logged to /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/ext/mysql2/gem_make.out
4

11 に答える 11

151

Ubuntu:

sudo apt-get install libmysqlclient-dev  #(mysql development headers)
sudo gem install mysql2 -- --with-mysql-dir=/etc/mysql/

それでおしまい!

結果:

Building native extensions. This could take a while...
Successfully installed mysql2-0.2.6
1 gem installed
Installing ri documentation for mysql2-0.2.6...
Enclosing class/module 'mMysql2' for class Result not known
Enclosing class/module 'mMysql2' for class Client not known
Installing RDoc documentation for mysql2-0.2.6...
Enclosing class/module 'mMysql2' for class Result not known
Enclosing class/module 'mMysql2' for class Client not known
于 2010-12-22T15:44:41.337 に答える
41

mysql2を正しくコンパイルするには、MySQL開発ヘッダーが必要です。機能の多くはCで記述され、その後MySQLに対してリンクされるため、これが必要です。

解決策は、gemインストーラーをmysqlインストールフォルダーに明示的に指定することです。

gem install mysql2 -- --with-mysql-dir=/usr/local/mysql
# or where ever you installed your mysql server to

または、mysqlサーバーを既知の場所にインストールして(たとえば、homebrewを使用して)、gemをインストールします。

# install the mysql server locally
brew install mysql
# install the gem
gem install mysql2

どちらのアプローチでも、必要なGCCコンパイラを使用するにはXCodeをインストールする必要があります。

于 2010-11-06T21:10:33.117 に答える
30

マシンに64ビットMySQLをインストールする必要があります。さらに、xcodeをインストールするときに入手できるビルドツールも必要です。

于 2010-11-06T21:03:50.937 に答える
27

BrewとMySQLをインストールした状態で、次を使用してmysql2gemをインストールしました

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

Bundlerを使用している場合は、次のコマンドでBundlerにこれを伝えることができます。

bundle config build.mysql2 --with-mysql-config=/usr/local//Cellar/mysql/5.5.10/bin/mysql_config

ここに記載されているように:http://gembundler.com/man/bundle-config.1.html

于 2012-02-19T12:16:00.723 に答える
8

Mac OSX Moutain Lionでは、以下のコマンドが機能しました。

gem install mysql2 -- --srcdir=/usr/local/mysql/include
于 2012-12-10T10:32:18.413 に答える
6

Ubuntu 15.04:

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

Ubuntu-16.04:

sudo apt-get install ruby-mysql2
sudo gem install mysql2

出力:

Building native extensions.  This could take a while...
Successfully installed mysql2-0.3.19
Parsing documentation for mysql2-0.3.19
Installing ri documentation for mysql2-0.3.19
Done installing documentation for mysql2 after 0 seconds
1 gem installed
于 2015-08-23T10:53:22.913 に答える
2

MySQL Webサイトでこのスレッドを確認することをお勧めします:http: //forums.mysql.com/read.php? 116,178217,178217、特にScott Derrickによる回答:http://forums.mysql.com/ read.php?116,178217,189357#msg-189357

具体的には、

sudo gem install mysql2 -- --with-mysql-dir=/usr/local/mysql

お役に立てば幸いです。

于 2010-11-06T21:04:31.853 に答える
1

私は2日分のインターネットとStackOverflowを調べましたが、このリンクを見つけてmysql2のこのチケットを使い始めるまで、実際に問題を解決しませんでした。

私のセットアップでは(チケットで説明されているように)、-Wno-null-conversion -Wno-unused-private-fieldのコンパイラスイッチが壊れて、正確に正しくないエラーが発生しました。これは次のとおりです。

mysql.h is missing. please check your installation of mysql and try again
于 2013-06-25T17:04:22.490 に答える
1

私はこれを解決するために、ディレクトリがどこにあるかを特定し、 brewやmacportsなどで何も再インストールする必要がなく、どこにあるかを指定するだけで解決しました(1つだけ:私のMacのルビーはrvmでインストールされました、私はos x)に付属しているデフォルトのものを使用しない:

gem install mysql2以下のフラグに追加します

  • --srcdir="..."-インクルード
  • --with-mysql-dir="..."-mysqlディレクトリ
  • --with-mysql-config="..."-mysql_configファイル

このようなgem install mysql2 --srcdir=/usr/local/mysql/include/ --with-mysql-dir=/usr/local/mysql --with-mysql-config=/usr/local/mysql/bin/mysql_config

于 2016-10-21T17:00:01.290 に答える
1

Centos 6.x(7は動作するはずです)とSCL(ソフトウェアコレクション)rh-mysql:

scl enable rh-mysql56 bash
gem install mysql2 -v '0.4.5' -- --with-mysql-include=/opt/rh/rh-mysql56/root/usr/include --with-mysql-lib=/opt/rh/rh-mysql56/root/usr/lib64
于 2016-11-26T04:24:29.647 に答える
0

rvm use ruby-2.1.0@rails4.0 --createディレクトリに入力すると機能すると思いますbundle install

于 2014-01-30T16:35:08.597 に答える