Ruby gem mysql2安装失败

时间:2010-11-06 20:57:12

标签: mysql ruby rubygems mysql2 libmysql

当我尝试安装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

11 个答案:

答案 0 :(得分:145)

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

答案 1 :(得分:40)

您需要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

这两种方法都要求您安装XCode以获得所需的GCC编译器。

答案 2 :(得分:26)

您必须在计算机上安装64位MySQL,以及安装xcode时获得的构建工具。

答案 3 :(得分:21)

安装了Brew和MySQL后,我使用以下命令安装mysql2 gem

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

答案 4 :(得分:7)

在Mac OS X Mountain Lion上,下面的命令对我有用:

gem install mysql2 -- --srcdir=/usr/local/mysql/include

答案 5 :(得分: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

答案 6 :(得分:2)

您可能想在MySQL网站上查看此主题: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

希望有所帮助。

答案 7 :(得分:1)

我挖了2天的互联网和Stack Overflow,直到我找到this link,然后开始通过this ticket for mysql2,我才真正解决了这个问题。

使用我的设置(如故障单中所述),-Wno-null-conversion -Wno-unused-private-field的编译器开关会中断并给我一个不完全正确的错误,即:< / p>

mysql.h is missing. please check your installation of mysql and try again

答案 8 :(得分:0)

我想如果您在目录中键入rvm use ruby-2.1.0@rails4.0 --create,那么bundle install就可以了。

答案 9 :(得分:0)

我通过具体了解目录的位置来解决这个问题,无需重新安装任何东西,使用brew或macports等等,只需指定事物的位置(只有一件事:ruby on我的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

答案 10 :(得分:0)

在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