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

Maz*_*aze 29 ruby mysql gem ruby-on-rails osx-snow-leopard

我在安装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
Run Code Online (Sandbox Code Playgroud)

当我使用rails server它时,出现了:

Could not find gem 'mysql2 (>= 0, runtime)' in any of the gem sources listed in your Gemfile.
Run Code Online (Sandbox Code Playgroud)

ALo*_*LoR 52

看来它找不到MySQL库.你安装了MySQL吗?
尝试通过自制程序安装它:

brew install mysql
Run Code Online (Sandbox Code Playgroud)

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

gem install mysql2
Run Code Online (Sandbox Code Playgroud)


Sus*_*ish 38

这个命令对我有用:

gem install mysql2 -- --srcdir=/usr/local/mysql/include
Run Code Online (Sandbox Code Playgroud)

  • 如果您使用mysql网站提供的二进制文件将其安装在Mac上,则可以使用此功能. (2认同)
  • 这对我有用,但是我使用了不同的目录。我用`locate mysql | grep include`并找到另一个目录。整个命令:`gem install mysql2 -v'0.3.21'---srcdir = / usr / local / Cellar / mysql / 8.0.12 / include (2认同)

Aam*_*mir 23

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

xxx =您要安装的mysql2的版本.

gem install mysql2 -v 'x.x.x' -- --srcdir=/usr/local/mysql/include
Run Code Online (Sandbox Code Playgroud)

  • OSX 10.13.5 和通过自制软件安装的 mysql 的快速说明:--srcdir 是:`/usr/local/include/mysql` (2认同)

Igo*_*ych 17

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

brew install mysql-connector-c
gem install mysql2
Run Code Online (Sandbox Code Playgroud)


Son*_*mar 7

要修复手动 gem 安装:

brew install openssl
gem install mysql2 -- --with-opt-dir="$(brew --prefix openssl)"
Run Code Online (Sandbox Code Playgroud)

要修复所有捆绑包安装:

brew install openssl
bundle config --global build.mysql2 --with-opt-dir="$(brew --prefix openssl)"
bundle install
Run Code Online (Sandbox Code Playgroud)