Rails 3:MySQL2 gem“库未加载”

时间:2011-11-02 00:00:18

标签: mysql ruby-on-rails-3

Derek-MacBook-Pro:example derek$ rails g
/Library/Ruby/Gems/1.8/gems/mysql2-0.3.7/lib/mysql2/mysql2.bundle: dlopen(/Library/Ruby/Gems/1.8/gems/mysql2-0.3.7/lib/mysql2/mysql2.bundle, 9): Library not loaded: libmysqlclient.18.dylib (LoadError)
  Referenced from: /Library/Ruby/Gems/1.8/gems/mysql2-0.3.7/lib/mysql2/mysql2.bundle
  Reason: image not found - /Library/Ruby/Gems/1.8/gems/mysql2-0.3.7/lib/mysql2/mysql2.bundle
    from /Library/Ruby/Gems/1.8/gems/mysql2-0.3.7/lib/mysql2.rb:9
    from /Library/Ruby/Gems/1.8/gems/bundler-1.0.11/lib/bundler/runtime.rb:68:in `require'
    from /Library/Ruby/Gems/1.8/gems/bundler-1.0.11/lib/bundler/runtime.rb:68:in `require'
    from /Library/Ruby/Gems/1.8/gems/bundler-1.0.11/lib/bundler/runtime.rb:66:in `each'
    from /Library/Ruby/Gems/1.8/gems/bundler-1.0.11/lib/bundler/runtime.rb:66:in `require'
    from /Library/Ruby/Gems/1.8/gems/bundler-1.0.11/lib/bundler/runtime.rb:55:in `each'
    from /Library/Ruby/Gems/1.8/gems/bundler-1.0.11/lib/bundler/runtime.rb:55:in `require'
    from /Library/Ruby/Gems/1.8/gems/bundler-1.0.11/lib/bundler.rb:120:in `require'
    from /Users/derek/example/config/application.rb:7
    from /Library/Ruby/Gems/1.8/gems/railties-3.0.10/lib/rails/commands.rb:15:in `require'
    from /Library/Ruby/Gems/1.8/gems/railties-3.0.10/lib/rails/commands.rb:15
    from script/rails:6:in `require'
    from script/rails:6

我在OS X Lion中安装并运行了MySQL。我安装了宝石。它出现在gem列表中(版本0.3.7)。有什么问题?

修改

在这里,我将添加我的database.yml文件。它说适配器在每种环境类型中都是mysql2。也许这会有所帮助:

# MySQL.  Versions 4.1 and 5.0 are recommended.
#
# Install the MySQL driver:
#   gem install mysql2
#
# And be sure to use new-style password hashing:
#   http://dev.mysql.com/doc/refman/5.0/en/old-client.html
development:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: example_development
  pool: 5
  username: root
  password:
  host: localhost

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: example_test
  pool: 5
  username: root
  password:
  host: localhost

production:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: example_production
  pool: 5
  username: root
  password:
  host: localhost

1 个答案:

答案 0 :(得分:0)

  • 确保'mysql2'是database.yml
  • 中指定的数据库适配器
  • 确保'mysql2'是Gemfile中指定的gem

我记得错过这两件事之一的错误实际上是不直观的,听起来像是在描述另一个......所以,只要确保两者都是正确的: - )