繁体   English   中英

Ruby gem mysql2安装失败

[英]Ruby gem mysql2 install failing

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

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服务器安装到已知位置(例如,使用homebrew ),然后安装gem

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

两种方法都要求您安装XCode才能具有所需的GCC编译器。

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

安装了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

在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网站上检查此线程: 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

希望能有所帮助。

我花了2天的时间浏览互联网和Stack Overflow,直到找到该链接 ,然后开始研究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或任何东西重新安装任何东西,只需指定东西在哪里(只有一件事:我的Mac上的ruby是通过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

在具有SCL(软件集合)rh-mysql的Centos 6.x(应该可以使用7)中:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM