Ruby gem mysql2 install failing

2019-01-04 18:19发布

When I try to install the mysql2 gem, it fails with no apparent errors. Does anyone know what to do to work around this so mysql2 installs?

Tanner-Smiths-MacBook-Pro:Humans_vs_Zombies_Parse tanner$ sudo gem install mysql2Building 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

11条回答
Summer. ? 凉城
2楼-- · 2019-01-04 18:47

With Brew and MySQL installed, I used the following to install the mysql2 gem

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

If you're using Bundler, you can tell bundler about this with command:

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

As documented here: http://gembundler.com/man/bundle-config.1.html

查看更多
叼着烟拽天下
3楼-- · 2019-01-04 18:47

You might want to check this thread at the MySQL web site: http://forums.mysql.com/read.php?116,178217,178217, particularly the answer by Scott Derrick: http://forums.mysql.com/read.php?116,178217,189357#msg-189357

To be more specific, try using

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

Hope that helps.

查看更多
时光不老,我们不散
4楼-- · 2019-01-04 18:49

In Centos 6.x (7 should work) with SCL (software collection) 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
查看更多
趁早两清
5楼-- · 2019-01-04 18:55

I guess that if you type rvm use ruby-2.1.0@rails4.0 --create in you directory then bundle install it works.

查看更多
够拽才男人
6楼-- · 2019-01-04 18:56

I solved this by being specific on where are the directories, no need to reinstall anything, with brew or macports or whatever, just by specifying where are the things (only one thing: the ruby on my mac was installed with rvm, I'm not using the default one that comes with os x):

adding to your gem install mysql2 the flags below

  • --srcdir="..." - the includes
  • --with-mysql-dir="..." - the mysql directory
  • --with-mysql-config="..." - the mysql_config file

like this gem install mysql2 --srcdir=/usr/local/mysql/include/ --with-mysql-dir=/usr/local/mysql --with-mysql-config=/usr/local/mysql/bin/mysql_config

查看更多
登录 后发表回答