当我尝试安装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
有帮助吗?

解决方案

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

其他提示

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

您需要MySQL开发标头才能正确编译。这是需要的,因为许多功能都是在C中编写的,随后与MySQL链接。

解决方案是将宝石安装程序指向您的mySQL安装文件夹,就像这样

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

或通过将MySQL Server安装到已知位置(例如,使用 自制。)然后安装宝石

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

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

安装了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天的互联网和堆栈溢出,直到我发现 这个链接 然后开始工作 这张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 有用。

我通过具体说明目录, 无需重新安装任何东西, ,使用酿造或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

在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
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top