我只是从Ruby(和Rails)开始。我使用http://ruby.railstutorial.org/ruby-on-rails-tutorial- book#sec:ruby gems 进行了设置rvm。我的一切都与sqlite配合良好。
rvm
现在,我想尝试将其转换为MySQL,因为这是我大部分开发工作的基础。在我的Gemfile中,我已将sqlite替换为mysql2:
group :development, :test do # gem 'sqlite3', '1.3.5' gem 'mysql2' gem 'rspec-rails', '2.9.0' end
但是,当我尝试在MySQL中为Rails创建数据库时,我得到了:
$ rake db:create --trace rake aborted! dlopen(/Users/username/.rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/mysql2-0.3.11/lib/mysql2/mysql2.bundle, 9): Library not loaded: libmysqlclient.18.dylib Referenced from: /Users/username/.rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/mysql2-0.3.11/lib/mysql2/mysql2.bundle Reason: image not found - /Users/username/.rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/mysql2-0.3.11/lib/mysql2/mysql2.bundle
我看过其他一些文章,建议通过家庭酿造重新安装MySQL(我的是通过可下载的DMG安装的),但是我不愿意这样做,因为我已经有了其他非红宝石项目的其他几个数据库。
实际上,我确实有Rails正在寻找的文件;它安装在中/usr/local/mysql/lib/libmysqlclient.18.dylib。告诉Rails如何定位的最佳方法是什么?
/usr/local/mysql/lib/libmysqlclient.18.dylib
解决方案非常简单;将库路径添加到〜/ .bash_profile或〜/ .profile文件中:
MYSQL=/usr/local/mysql/bin export PATH=$PATH:$MYSQL export DYLD_LIBRARY_PATH=/usr/local/mysql/lib:$DYLD_LIBRARY_PATH
如果仍然无法正常工作(对我来说这样):
sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib
有很多带有的博客install_name_tool,它们对我不起作用,因为我在OSX Lion上:
install_name_tool
sudo install_name_tool -change libmysqlclient.18.dylib /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/local/bin/indexer sudo install_name_tool -change libmysqlclient.18.dylib /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/local/bin/search