数据库
首页 > 数据库> > 用RVM在mac上安装mysql2 gem真的很痛苦吗?

用RVM在mac上安装mysql2 gem真的很痛苦吗?

作者:互联网

步骤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>'

第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

结果: –

    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>'

第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

当前状态: –

ruby-v

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

rails -v

Rails 3.0.3

宝石清单

*** 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)

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

捆绑显示mysql2

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

找到libmysqlclient.16.dylib

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

有谁能够帮我?

解决方法:

我有山姆问题.我做的是做什么;

gem install --version '0.2.7' mysql2

然后在你的Rails的GemFile上.应该是这样的.

gem 'mysql2', '0.2.7'

然后再试一次.希望它有所帮助.

标签:mysql,installation,ruby-on-rails-3,macos,mysql2
来源: https://codeday.me/bug/20190715/1471405.html