Ruby Gem mysql2インストールの失敗
質問
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
解決
マシンに64ビットMySQLをインストールする必要があります。また、Xcodeをインストールすると得られるビルドツールが必要です。
他のヒント
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
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サーバーを既知の場所にインストールすることによって(例: ホームブリュー。)そして、宝石のインストール
# install the mysql server locally
brew install mysql
# install the gem
gem install mysql2
どちらのアプローチでも、必要なGCCコンパイラを持つためにXcodeをインストールする必要があります。
BrewとMySQLをインストールした状態で、MySQL2 GEMをインストールするために以下を使用しました
gem install mysql2 -- --with-mysql-config=/usr/local/Cellar/mysql/5.5.10/bin/mysql_config
バンドラーを使用している場合、コマンドでこれについてバンドラーに伝えることができます。
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
Mac OSX Moutain Lionで、コマンドの下で私のために働いた:
gem install mysql2 -- --srcdir=/usr/local/mysql/include
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
MySQL Webサイトでこのスレッドを確認することをお勧めします。 http://forums.mysql.com/read.php?116,178217,178217, 、特にスコット・デリックによる答え: http://forums.mysql.com/read.php?116,178217,189357#msg-189357
より具体的には、使用してみてください
sudo gem install mysql2 -- --with-mysql-dir=/usr/local/mysql
それが役立つことを願っています。
私はインターネットとスタックのオーバーフローを2日間掘りました、そしてそれは私が見つけるまでではありませんでした このリンク そして、作業を開始します MySQL2のこのチケット 私が実際に問題を解決したこと。
私のセットアップ(チケットで説明されているように)を使用すると、-WNO-Null-Conversion -WNO-Unused-Private-Fieldのコンパイラスイッチは壊れて、正確ではないエラーを与えてくれます。
mysql.h is missing. please check your installation of mysql and try again
入力すると思います rvm use ruby-2.1.0@rails4.0 --create
その後、ディレクトリに bundle install
できます。
ディレクトリはどこにあるかについて具体的にこれを解決しました、 何も再インストールする必要はありません, 、brewやmacportsなど、物事はどこにあるのかを指定するだけで(1つだけ:Ruby on My 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
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