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
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?
$ 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(11)
乌班图:
就是这样!
结果:
Ubuntu:
That's it!
Result:
您需要 MySQL 开发头文件才能正确编译 mysql2。这是必要的,因为大部分功能都是用 C 编写的,然后与 MySQL 链接。
解决方案是将 gem 安装程序明确指向您的 mysql 安装文件夹
,或者将 mysql 服务器安装到已知位置(例如,使用 homebrew。)然后安装 gem
这两种方法都要求您安装 XCode 以获得所需的 GCC 编译器。
You need the MySQL development headers for mysql2 to properly compile. This is needed, because much of the functionality is written in C and subsequently linked against MySQL.
A solution is to either point the gem installer to your mysql install folder explicitly like so
or by installing a mysql server to a known location (e.g. by using homebrew.) and then installing the gem
Both approaches require you to have XCode installed to have the required GCC compiler.
您的计算机上必须安装 64 位 MySQL,以及安装 xcode 时获得的构建工具。
You have to have 64-bit MySQL installed on your machine, plus the build tools you get when you install xcode.
安装了 Brew 和 MySQL 后,我使用以下命令来安装 mysql2 gem
如果您使用 Bundler,您可以使用命令告诉捆绑程序:
如此处所述: http://gembundler.com/man/bundle-config.1.html
With Brew and MySQL installed, I used the following to install the mysql2 gem
If you're using Bundler, you can tell bundler about this with command:
As documented here: http://gembundler.com/man/bundle-config.1.html
在 Mac OSX Moutain Lion 上,以下命令对我有用:
on Mac OSX Moutain Lion, below command worked for me:
Ubuntu 15.04:
Ubuntu-16.04:
输出:
Ubuntu 15.04:
Ubuntu-16.04:
Output:
您可能需要在 MySQL 网站上查看此线程:http://forums。 mysql.com/read.php?116,178217,178217,特别是 Scott Derrick 的回答:http://forums.mysql.com/read.php?116,178217,189357#msg-189357
要更具体,请尝试使用
希望有帮助。
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
Hope that helps.
在 Centos 6.x(7 应该可以)中使用 SCL(软件集合)rh-mysql:
In Centos 6.x (7 should work) with SCL (software collection) rh-mysql:
我花了两天时间在互联网和 Stack Overflow 上进行了研究,直到我发现 此链接,然后开始处理 这张 mysql2 的票表明我实际上解决了这个问题。
根据我的设置(如票证中所述), -Wno-null-conversion -Wno-unused-private-field 的编译器开关会中断并给我一个不完全正确的错误,即:
I dug through 2 days worth of the internet and Stack Overflow, and it wasn't until I found this link and then starting working through this ticket for mysql2 that I actually resolved the issue.
With my setup (as explained in the ticket), the compiler switches of -Wno-null-conversion -Wno-unused-private-field would break and give me an error that wasn't exactly correct, which was:
我通过具体说明目录在哪里解决了这个问题,不需要重新安装任何东西,使用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
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 filelike this
gem install mysql2 --srcdir=/usr/local/mysql/include/ --with-mysql-dir=/usr/local/mysql --with-mysql-config=/usr/local/mysql/bin/mysql_config
我想如果您输入
rvm 使用 [email protected] - -在您的目录中创建
,然后捆绑安装
就可以了。I guess that if you type
rvm use [email protected] --create
in you directory thenbundle install
it works.