使用Mac OSX 10.6为Ruby on Rails安装mysql2 gem

问题描述 投票:28回答:10

我在安装mysql2 gem时遇到问题。

当我做gem install mysql2时,这就出现了:

Marks-MacBook-Pro:~ Mark$ gem install mysql2
Building native extensions.  This could take a while...
ERROR:  Error installing mysql2:
ERROR: Failed to build gem native extension.

/Users/useruser/.rvm/rubies/ruby-1.9.2-p136/bin/ruby extconf.rb
checking for rb_thread_blocking_region()... yes
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=/Users/useruser/.rvm/rubies/ruby-1.9.2-p136/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 /Users/useruser/.rvm/gems/ruby-1.9.2-p136/gems/mysql2-0.2.6 for inspection.
Results logged to /Users/useruser/.rvm/gems/ruby-1.9.2-p136/gems/mysql2-0.2.6/ext/mysql2/gem_make.out

此外,当我使用rails server时,这会出现:

Could not find gem 'mysql2 (>= 0, runtime)' in any of the gem sources listed in your Gemfile.
mysql ruby-on-rails ruby osx-snow-leopard gem
10个回答
50
投票

看来它找不到MySQL库。你安装了MySQL吗? 尝试通过homebrew安装它:

brew install mysql

或者通过macports或fink或任何你喜欢的方式安装它,然后再试一次:

gem install mysql2

0
投票

我知道这已被多次回答了,这里有什么对我有用:2019年5月20日OSX Mojave 10.14.4 MySQL Ver 14.14 Distrib 5.7.24,for osx10.14(x86_64)使用EditLine wrapper ruby​​ 2.5.0p0(2017 -12-25修订版61468)[x86_64-darwin17] Rails 5.2.1

export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/
gem install mysql2 -- --with-mysql-config=/usr/local/Cellar/mysql\@5.7/5.7.24/bin/mysql_config

将“/usr/local/Cellar/[email protected]/5.7.24/bin/mysql_config”更改为当前有效路径来自“/ usr / local / Cellar / mysql”

希望这可以帮助!


37
投票

这个命令对我有用:

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

22
投票

以下命令成功地为我工作。

x.x.x =您要安装的mysql2版本。

gem install mysql2 -v 'x.x.x' -- --srcdir=/usr/local/mysql/include

17
投票

我在Mac OS X上不需要MySQL,因为我在Vagrant盒子上安装了MySQL。因此,我刚刚安装了mysql-connector-c。

brew install mysql-connector-c
gem install mysql2

4
投票

以下对我有用

brew install mysql 
brew install mysql-connector-c
gem install mysql2

4
投票

如果您使用自制软件安装mysql,brew install mysql,这对我有用:

gem install mysql2 -v 'x.x.x' -- --with-mysql-config=/usr/local/Cellar/mysql/y.y.y/bin/mysql_config

x.x.x =您要安装的mysql2 gem的版本 y.y.y =您已安装ls /usr/local/Cellar/mysql以找到它的mysql版本。

获取mysql的版本

brew info mysql                                                                                                                                                                                                     
mysql: stable 5.7.19 (bottled)
               ...
/usr/local/Cellar/mysql/5.7.19 (322 files, 233MB) *

               ...

那么如果你想用bundle安装:

bundle config build.mysql --with-mysql-config=/usr/local/Cellar/mysql/y.y.y/bin/mysql_config

3
投票

您必须指定一些其他环境变量才能在Mac OSX 10.6的64位架构上安装此gem:

env ARCHFLAGS="-arch x86_64" gem install mysql2

如果您使用的是rvm,可以在〜/ .rvmrc文件中将其添加为默认选项:

rvm_archflags="-arch x86_64"

1
投票

我有完全相同的问题和错误尝试安装mysql2。我认为我的mamp安装的MySQL可以正常工作并花了几个小时来玩这些工作的路径 - 没有成功。

终于从ALoR发现了这篇文章并通过自制软件安装了一个新版本 - 但是 - 请务必遵循自制软件中的所有说明!我错过了几步,浪费了另一个小时来追踪这个问题 - 这里是那些指示:https://stackoverflow.com/a/11061487/1241271

MySQL成功安装后,我运行:sudo gem install mysql2,它就像一个魅力。

希望这可以帮助某人浪费几个小时,因为他们忽略了阅读文档(newb错误)。


0
投票

确保通过Homebrew在Mac上安装openssl。

brew install openssl

Install mysql2 gem.

gem install mysql2 -v '0.5.2' -- --with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/i
© www.soinside.com 2019 - 2024. All rights reserved.