简体   繁体   中英

Rails 3: MySQL2 gem “Library Not Loaded”

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

I have MySQL installed and running in OS X Lion. I have the gem installed. It appears in the gem list (version 0.3.7). What is wrong?

Edit:

Here, I will add my database.yml file. It says the adapter is mysql2 in every environment type. Maybe this will help:

# 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
  • Make sure that 'mysql2' is the db adapter specified in your database.yml
  • Make sure that 'mysql2' is the gem specified in your Gemfile

I remember that the error for one of those two things missing is really unintuitive and sounds like it's describing the other... so, just make sure both are correct :-)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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