MySQL Ruby gem mysql2 安装失败

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4115126/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 17:38:41  来源:igfitidea点击:

Ruby gem mysql2 install failing

mysqlrubyrubygemsmysql2libmysql

提问by Tanner

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?

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

采纳答案by coreyward

You have to have 64-bit MySQL installed on your machine, plus the build tools you get when you install xcode.

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

回答by tunelko

Ubuntu:

Ubuntu:

sudo apt-get install libmysqlclient-dev  #(mysql development headers)
sudo gem install mysql2 -- --with-mysql-dir=/etc/mysql/

That's it!

就是这样!

Result:

结果:

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

回答by Holger Just

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.

您需要 mysql2 的 MySQL 开发头文件才能正确编译。这是必需的,因为大部分功能是用 C 编写的,随后链接到 MySQL。

A solution is to either point the gem installer to your mysql install folder explicitly like so

一种解决方案是将 gem 安装程序明确指向您的 mysql 安装文件夹,如下所示

gem install mysql2 -- --with-mysql-dir=/usr/local/mysql
# or where ever you installed your mysql server to

or by installing a mysql server to a known location (e.g. by using homebrew.) and then installing the gem

或者通过将 mysql 服务器安装到已知位置(例如通过使用homebrew。)然后安装 gem

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

Both approaches require you to have XCode installed to have the required GCC compiler.

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

回答by dkam

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

安装 Brew 和 MySQL 后,我使用以下命令安装 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:

如果你使用 Bundler,你可以用命令告诉 bundler:

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

如此处所述:http: //gembundler.com/man/bundle-config.1.html

回答by Sushma Satish

on Mac OSX Moutain Lion, below command worked for me:

在 Mac OSX 山狮上,以下命令对我有用:

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

回答by shilovk

Ubuntu 15.04:

Ubuntu 15.04:

sudo apt-get install libmysqlclient-dev
sudo gem install mysql2

Ubuntu-16.04:

Ubuntu-16.04:

sudo apt-get install ruby-mysql2
sudo gem install mysql2

Output:

输出:

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

回答by rleber

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

您可能想在 MySQL 网站上查看此线程:http: //forums.mysql.com/read.php?116,178217,178217,尤其是 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.

希望有帮助。

回答by AnthonyAlmighty

I dug through 2 days worth of the internet and Stack Overflow, and it wasn't until I found this linkand then starting working through this ticket for mysql2that I actually resolved the issue.

我挖掘了 2 天的互联网和 Stack Overflow,直到我找到了这个链接,然后开始处理mysql2 的这张票,我才真正解决了这个问题。

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:

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

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

回答by AnthonyAlmighty

I guess that if you type rvm use [email protected] --createin you directory then bundle installit works.

我想如果你输入rvm use [email protected] --create你的目录,那么bundle install它就可以工作了。

回答by vic

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):

我通过具体说明目录在哪里解决了这个问题,不需要重新安装任何东西,使用 brew 或 macports 或其他任何东西,只需指定东西在哪里(只有一件事:我的 mac 上的 ruby​​ 是用 rvm 安装的,我是不使用 os x 附带的默认值):

adding to your gem install mysql2the flags below

添加到您gem install mysql2的以下标志

  • --srcdir="..."- the includes
  • --with-mysql-dir="..."- the mysql directory
  • --with-mysql-config="..."- the mysql_config file
  • --srcdir="..."- 包括
  • --with-mysql-dir="..."- mysql 目录
  • --with-mysql-config="..."- mysql_config 文件

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

像这样 gem install mysql2 --srcdir=/usr/local/mysql/include/ --with-mysql-dir=/usr/local/mysql --with-mysql-config=/usr/local/mysql/bin/mysql_config