简体   繁体   English

使用 RVM 在 Mac 上安装 mysql2 gem 真的很痛苦

[英]Installing mysql2 gem on mac with RVM is real pain

Step 1:--步骤1: -

    rails s/usr/local/rvm/gems/ruby-1.9.2-p180/gems/mysql2-0.3.2/lib/mysql2.rb:8:in `require': dlopen(/usr/local/rvm/gems/ruby-1.9.2-p180/gems/mysql2-0.3.2/lib/mysql2/mysql2.bundle, 9): Library not loaded: libmysqlclient.16.dylib (LoadError)
    Referenced from: /usr/local/rvm/gems/ruby-1.9.2-p180/gems/mysql2-0.3.2/lib/mysql2/mysql2.bundle
    Reason: image not found - /usr/local/rvm/gems/ruby-1.9.2-p180/gems/mysql2-0.3.2/lib/mysql2/mysql2.bundle
    from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/mysql2-0.3.2/lib/mysql2.rb:8:in `<top (required)>'
    from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/runtime.rb:68:in `require'
    from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/runtime.rb:68:in `block (2 levels) in require'
    from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/runtime.rb:66:in `each'
    from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/runtime.rb:66:in `block in require'
    from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/runtime.rb:55:in `each'
    from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/runtime.rb:55:in `require'
    from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler.rb:120:in `require'
    from /Users/mohit/projects/lbs_admin/config/application.rb:7:in `<top (required)>'
    from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.3/lib/rails/commands.rb:28:in `require'
    from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.3/lib/rails/commands.rb:28:in `block in <top (required)>'
    from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.3/lib/rails/commands.rb:27:in `tap'
    from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.3/lib/rails/commands.rb:27:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

STEP 2:--第2步: -

 sudo install_name_tool -change libmysqlclient.16.dylib /usr/local/mysql-5.5.9-osx10.6-x86_64/lib/libmysqlclient.16.dylib /usr/local/rvm/gems/ruby-1.9.2-p180/gems/mysql2-0.3.2/lib/mysql2/mysql2.bundle

Result:--结果: -

    rails sWARNING: This version of mysql2 (0.3.2) doesn't ship with the ActiveRecord adapter bundled anymore as it's now part of Rails 3.1
    WARNING: Please use the 0.2.x releases if you plan on using it in Rails <= 3.0.x
    => Booting WEBrick
    => Rails 3.0.3 application starting in development on http://0.0.0.0:3000
    => Call with -d to detach
    => Ctrl-C to shutdown server
    Exiting
    /usr/local/rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.3/lib/active_record/connection_adapters/abstract/connection_specification.rb:71:in `rescue in establish_connection': Please install the mysql2 adapter: `gem install activerecord-mysql2-adapter` (no such file to load -- active_record/connection_adapters/mysql2_adapter) (RuntimeError)
        from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.3/lib/active_record/connection_adapters/abstract/connection_specification.rb:68:in `establish_connection'
        from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.3/lib/active_record/connection_adapters/abstract/connection_specification.rb:60:in `establish_connection'
        from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.3/lib/active_record/connection_adapters/abstract/connection_specification.rb:55:in `establish_connection'
        from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.3/lib/active_record/railtie.rb:59:in `block (2 levels) in <class:Railtie>'
        from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.3/lib/active_support/lazy_load_hooks.rb:36:in `instance_eval'
        from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.3/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
        from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.3/lib/active_support/lazy_load_hooks.rb:43:in `block in run_load_hooks'
        from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.3/lib/active_support/lazy_load_hooks.rb:42:in `each'
        from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.3/lib/active_support/lazy_load_hooks.rb:42:in `run_load_hooks'
        from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.3/lib/active_record/base.rb:1891:in `<top (required)>'
        from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/will_paginate-3.0.pre2/lib/will_paginate/finders/active_record.rb:31:in `enable!'
        from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/will_paginate-3.0.pre2/lib/will_paginate/railtie.rb:9:in `block in <class:Railtie>'
        from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.3/lib/rails/initializable.rb:25:in `instance_exec'
        from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.3/lib/rails/initializable.rb:25:in `run'
        from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.3/lib/rails/initializable.rb:50:in `block in run_initializers'
        from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.3/lib/rails/initializable.rb:49:in `each'
        from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.3/lib/rails/initializable.rb:49:in `run_initializers'
        from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.3/lib/rails/application.rb:134:in `initialize!'
        from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.3/lib/rails/application.rb:77:in `method_missing'
        from /Users/mohit/projects/lbs_admin/config/environment.rb:5:in `<top (required)>'
        from /Users/mohit/projects/lbs_admin/config.ru:3:in `require'
        from /Users/mohit/projects/lbs_admin/config.ru:3:in `block in <main>'
        from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/rack-1.2.2/lib/rack/builder.rb:46:in `instance_eval'
        from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/rack-1.2.2/lib/rack/builder.rb:46:in `initialize'
        from /Users/mohit/projects/lbs_admin/config.ru:1:in `new'
        from /Users/mohit/projects/lbs_admin/config.ru:1:in `<main>'
        from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/rack-1.2.2/lib/rack/builder.rb:35:in `eval'
        from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/rack-1.2.2/lib/rack/builder.rb:35:in `parse_file'
        from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/rack-1.2.2/lib/rack/server.rb:162:in `app'
        from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/rack-1.2.2/lib/rack/server.rb:248:in `wrapped_app'
        from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/rack-1.2.2/lib/rack/server.rb:213:in `start'
        from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.3/lib/rails/commands/server.rb:65:in `start'
        from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.3/lib/rails/commands.rb:30:in `block in <top (required)>'
        from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.3/lib/rails/commands.rb:27:in `tap'
        from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.3/lib/rails/commands.rb:27:in `<top (required)>'
        from script/rails:6:in `require'
        from script/rails:6:in `<main>'

Step 3:--第三步:--

sudo gem uninstall mysql2
sudo env ARCHFLAGS="-arch i386" gem install mysql2 -- --with-mysql-config=/usr/local/mysql-5.5.9-osx10.6-x86_64/bin/mysql_config

Current status:--当前状态: -

ruby -v ruby -v

ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-darwin10.7.0]

rails -v导轨-v

Rails 3.0.3导轨 3.0.3

gem list宝石清单

*** LOCAL GEMS ***

abstract (1.0.0)
actionmailer (3.0.7, 3.0.3)
actionpack (3.0.7, 3.0.3)
activemodel (3.0.7, 3.0.3)
activerecord (3.0.7, 3.0.3)
activeresource (3.0.7, 3.0.3)
activesupport (3.0.7, 3.0.3)
annotate-models (1.0.4)
arel (2.0.9)
builder (2.1.2)
bundler (1.0.12)
erubis (2.6.6)
i18n (0.5.0)
mail (2.2.19)
mime-types (1.16)
mysql2 (0.3.2)
polyglot (0.3.1)
rack (1.2.2)
rack-mount (0.6.14)
rack-test (0.5.7)
rails (3.0.7, 3.0.3)
railties (3.0.7, 3.0.3)
rake (0.8.7)
thor (0.14.6)
treetop (1.4.9)
tzinfo (0.3.27)
web-app-theme (0.6.3)
will_paginate (3.0.pre2)

locate mysql_config找到 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

bundle show mysql2捆绑显示 mysql2

 /usr/local/rvm/gems/ruby-1.9.2-p180/gems/mysql2-0.3.2

locate libmysqlclient.16.dylib找到 libmysqlclient.16.dylib

/usr/local/mysql-5.5.9-osx10.6-x86_64/lib/libmysqlclient.16.dylib

How can I proceed?我该如何进行?

I have the sam problem.我有同样的问题。 What I did is doing;我所做的是在做;

gem install --version '0.2.7' mysql2

Then on your Rails's GemFile.然后在 Rails 的 GemFile 上。 Should look like this.应该是这样的。

gem 'mysql2', '0.2.7'

Then try again.然后再试一次。 Hope it help.希望它有所帮助。

rails sWARNING: This version of mysql2 (0.3.2) doesn't ship with the ActiveRecord adapter bundled anymore as it's now part of Rails 3.1 WARNING: Please use the 0.2.x releases if you plan on using it in Rails <= 3.0.x rails 警告:此版本的 mysql2 (0.3.2) 不再随附捆绑的 ActiveRecord 适配器,因为它现在是 Rails 3.1 的一部分警告:如果您计划在 Rails <= 3.0 中使用它,请使用 0.2.x 版本。 X

MySql version '0.2.7' solved my issue. MySql 版本“0.2.7”解决了我的问题。

 gem 'mysql2', '0.2.7'

Your stacktrace after Step 2 told you what to do:第 2 步之后的堆栈跟踪告诉您该怎么做:

Please install the mysql2 adapter: gem install activerecord-mysql2-adapter请安装 mysql2 适配器: gem install activerecord-mysql2-adapter

Update更新

Also, upgrade your Rails to 3.0.7 - there are a number of security holes (and bugs) in 3.0.3.此外,将您的 Rails 升级到 3.0.7 - 3.0.3 中有许多安全漏洞(和错误)。

Update更新

Looks like that error message from Rails is wrong, it should have read:看起来来自 Rails 的错误消息是错误的,它应该是:

Please use the 0.2.x releases if you plan on using it in Rails <= 3.1如果您打算在 Rails <= 3.1 中使用它,请使用 0.2.x 版本

Ie. IE。 for anything less than 3.1 you need to pin mysql2 to the 0.2 release, and not allow it to use 0.3.对于低于 3.1 的任何版本,您需要将 mysql2 固定到 0.2 版本,并且不允许它使用 0.3。 To do this, change your mysql2 line in your Gemfile to this:为此,请将 Gemfile 中的 mysql2 行更改为:

gem "mysql2", "~> 0.2"

Then re-run bundle install然后重新运行bundle install

Try this (but I cannot guarantee anything)试试这个(但我不能保证什么)

  • Check this post about how to检查这篇文章关于如何
    • remove MySQL 5.5.删除 MySQL 5.5。
    • install MySQL 5.1 (I think I downloaded the 32bit DMG version)安装MySQL 5.1 (我想我下载的是32位DMG版本)
  • Follow this post to create the GEM.按照这篇文章创建 GEM。

Hopefully it will work after this.希望在此之后它会起作用。 I'll cross my fingers for you.我会为你交叉手指。

The above problem occurs presently on EngineYard App Cloud with Ruby 1.9.2 and Rails 3.0.3.上述问题目前出现在 EngineYard App Cloud 上,使用 Ruby 1.9.2 和 Rails 3.0.3。 Using mysql 2.8.1 barfs b/c EY sets mysql2 adapter.使用 mysql 2.8.1 barfs b/c EY 设置 mysql2 适配器。 Using mysql2 0.3.2 barfs.使用 mysql2 0.3.2 barfs。 So I was seriously stumped.所以我被严重难住了。 Props to Richard Soutar's answer.支持 Richard Soutar 的回答。 It worked.有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM