启动 Rails 服务器时出现以下错误:
$ rails server
/Users/ssmith/.rvm/gems/ruby-1.9.2-p0/gems/mysql2-0.2.6/lib/mysql2.rb:7:in `require': dlopen(/Users/ssmith/.rvm/gems/ruby-1.9.2-p0/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle, 9): Library not loaded: libmysqlclient.16.dylib (LoadError)
Referenced from: /Users/ssmith/.rvm/gems/ruby-1.9.2-p0/gems/mysql2- 0.2.6/lib/mysql2/mysql2.bundle
Reason: image not found - /Users/ssmith/.rvm/gems/ruby-1.9.2-p0/gems/mysql2-
0.2.6/lib/mysql2/mysql2.bundle
在 rvm use ruby-1.9.2-p0 命令之后,我使用以下命令安装了 mysql2:
$ gem install mysql2 -- --with-mysql-dir=/usr/local/mysql --with-mysql-config=/usr/local/mysql/bin/mysql_config
Building native extensions. This could take a while...
Successfully installed mysql2-0.2.6
1 gem installed
Installing ri documentation for mysql2-0.2.6...
Enclosing class/module 'mMysql2' for class Client not known
Installing RDoc documentation for mysql2-0.2.6...
Enclosing class/module 'mMysql2' for class Client not known
我的 Gemfile 和 database.yml 文件中都有 mysql2,并且捆绑安装完成得很好
$ bundle show mysql2
/Users/ssmith/.rvm/gems/ruby-1.9.2-p0/gems/mysql2-0.2.6
我知道 Rails 服务器错误是由于它不知道 OSX 上的 mysql_config 位置,但是在 gem install 上我指定了正确的位置。然而,RVM 的 gem 似乎并不尊重 mysql_config 的位置。
有人对此有解决方案吗?