【问题标题】:issue in installing mysql2 gem with rails3 on mac在 mac 上使用 rails3 安装 mysql2 gem 的问题
【发布时间】:2011-02-17 02:06:23
【问题描述】:
 Installing mysql2 (0.2.6) with native extensions /Library/Ruby/Site/1.8/rubygems/installer.rb:483:in `build_extensions': ERROR: Failed to build gem native extension. (Gem::Installer::ExtensionBuildError)

/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb 
mkmf.rb can't find header files for ruby at /System/Library/Frameworks/Ruby.framework  /Versions/1.8/usr/lib/ruby/ruby.h


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
from /Library/Ruby/Site/1.8/rubygems/installer.rb:446:in `each'
from /Library/Ruby/Site/1.8/rubygems/installer.rb:446:in `build_extensions'
from /Library/Ruby/Site/1.8/rubygems/installer.rb:198:in `install'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.10/lib/bundler/source.rb:96:in `install'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.10/lib/bundler/installer.rb:55:in `run'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.10/lib/bundler/spec_set.rb:12:in `each'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.10/lib/bundler/spec_set.rb:12:in `each'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.10/lib/bundler/installer.rb:44:in `run'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.10/lib/bundler/installer.rb:8:in `install'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.10/lib/bundler/cli.rb:226:in `install'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.10/lib/bundler/vendor/thor/task.rb:22:in `send'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.10/lib/bundler/vendor/thor/task.rb:22:in `run'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.10/lib/bundler/vendor/thor/invocation.rb:118:in `invoke_task'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.10/lib/bundler/vendor/thor.rb:246:in `dispatch'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.10/lib/bundler/vendor/thor/base.rb:389:in `start'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.10/bin/bundle:13
from /usr/bin/bundle:19:in `load'
from /usr/bin/bundle:19

编辑

  Mohit-Jains-MacBook-Pro:casecreed mohit$ locate mysql_config
 /Applications/XAMPP/xamppfiles/bin/mysql_config
 /usr/local/mysql-5.5.9-osx10.6-x86_64/bin/mysql_config
 /usr/local/mysql-5.5.9-osx10.6-x86_64/man/man1/mysql_config.1

按照你的建议做了之后……

     sudo gem install mysql2 -- –with-mysql-config=/usr/local/mysql-5.5.9-osx10.6-x86_64/bin/mysql_config

这是错误..

    Mohit-Jains-MacBook-Pro:casecreed mohit$ rake db:create
    (in /Users/mohit/projects/casecreed)
    rake aborted!
    dlopen(/Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle, 9): Library not loaded: libmysqlclient.16.dylib
      Referenced from: /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle
      Reason: image not found - /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle
    /Users/mohit/projects/casecreed/Rakefile:4
    (See full trace by running task with --trace

EDIT2

screenshot回答修改后的全过程..

Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
Couldn't create database for {"reconnect"=>false, "encoding"=>"utf8", "username"=>"root", "adapter"=>"mysql2", "database"=>"the_casecreed_test", "host"=>"localhost", "pool"=>5, "password"=>nil}, charset: utf8, collation: utf8_unicode_ci
Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
Couldn't create database for {"reconnect"=>false, "encoding"=>"utf8", "username"=>"root", "adapter"=>"mysql2", "database"=>"the_casecreed_development", "host"=>"localhost", "pool"=>5, "password"=>nil}, charset: utf8, collation: utf8_unicode_ci

EDIT3

development.yml

EDIT4

连mysql都连接不上。

Check this screenshot.

EDIT5

这是解决方案,但我无法理解,为什么 mysql 服务器没有启动..

Screenshot

【问题讨论】:

  • 看起来您缺少 ruby​​ 开发包。或者你可以试试bitnami.org/stack/rubystack
  • 我强烈推荐你用 RVM 安装 ruby​​,用 homebrew 安装 mysql。这很简单,这行得通。
  • @apneadiving 这有什么需要?我只想安装 mysql2 gem 就是这样。它在我的 linux 机器上完美运行。刚买了macbook pro,安装不了。。

标签: mysql ruby-on-rails ruby-on-rails-3 rubygems


【解决方案1】:

试试下面的,好像有worked for others

  1. 从终端运行locate mysql_config 并确定mysql_config 二进制文件的路径
  2. 在以下命令中使用该路径来安装 gem:sudo gem install mysql2 -- –with-mysql-config=/path/you/identified/above/mysql_config

[编辑]

响应新的错误,例如:

Mohit-Jains-MacBook-Pro:casecreed mohit$ rake db:create
(in /Users/mohit/projects/casecreed)
rake aborted!
dlopen(/Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle, 9): Library not loaded: libmysqlclient.16.dylib
  Referenced from: /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle
  Reason: image not found - /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle
/Users/mohit/projects/casecreed/Rakefile:4
(See full trace by running task with --trace

我相信这是由于 mysql2 没有使用 libmysqlclient.16.dylib 的完整路径。其他人很幸运:

sudo install_name_tool -change libmysqlclient.16.dylib /usr/local/mysql/lib/libmysqlclient.16.dylib /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle

但是,请务必将/usr/local/mysql/lib/libmysqlclient.16.dylib 替换为您自己的libmysqlclient.16.dylib 的路径。我不确定它会是什么,但您可以通过locate 找到它(如果没有,请在lib 目录中查看/usr/local/mysql-5.5.9-osx10.6-x86_64)。

【讨论】:

  • @Brandon Tilley 酷..我们似乎退出克隆..你可以检查edit2部分..添加截图..非常感谢...
  • 这很有趣;我知道这听起来很傻,但是您能否仔细检查您的 config/database.yml 以确保您的 development 部分中没有“套接字”条目?
  • @Brandon Tilley 是的,没有这样的...检查edit3。呃……我想我买这台 Mac 是个错误……Ubuntu 太好了……我想我应该搬回去扔掉这台该死的机器……
  • @Brandon Tilley 检查 edit3 和 edit4.. 我无法使用命令行连接到 mysql。
  • “我想我买这台 Mac 是个错误。Ubuntu 太好了。我想我应该搬回去扔掉这该死的机器。” ...或者至少把它还给 Mohit Jain ;-P
【解决方案2】:

从这里下载 64 位,然后尝试安装 mysql2 gem

http://dev.mysql.com/downloads/mysql/

它会起作用的..

【讨论】:

    【解决方案3】:

    尝试从 macports 安装 mysql

    sudo ports install mysql5
    

    花了很长时间才完成,但一旦完成就运行

    gem install mysql2
    

    一切正常

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-18
      • 2011-11-16
      • 2013-06-05
      • 2011-08-14
      相关资源
      最近更新 更多