OSX上的rails + MySQL:未加载库:libmysqlclient.18.dylib [英] rails + MySQL on OSX: Library not loaded: libmysqlclient.18.dylib

查看:86
本文介绍了OSX上的rails + MySQL:未加载库:libmysqlclient.18.dylib的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是从Ruby(和Rails)入手.我根据 http://ruby.railstutorial.org进行了设置/ruby​​-on-rails-tutorial-book#sec:ruby 宝石,使用rvm.我让sqlite一切正常.

I'm just starting out with Ruby (and rails). I did the setup according to http://ruby.railstutorial.org/ruby-on-rails-tutorial-book#sec:ruby gems, using rvm. I have everything working well with sqlite.

现在,我想尝试将其转换为MySQL,因为这是我大部分开发工作的基础.在我的Gemfile中,我已将sql2替换为mysql2:

Now I'd like to try converting things over to MySQL, since that's what I do most of my development with. In my Gemfile I've replaced sqlite with mysql2:

group :development, :test do
#  gem 'sqlite3', '1.3.5'
  gem 'mysql2'
  gem 'rspec-rails', '2.9.0'
end

但是当我尝试在MySQL中为Rails创建数据库时,我得到了:

But when I try to create the DB for rails in MySQL I get:

$ 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安装的),但我不想这样做,因为我已经在其中有其他非红宝石项目的其他几个数据库了

I've seen other postings recommending re-installing MySQL via homebrew (mine was installed via a downloadable DMG), but I'd prefer not to do that as I have several other databases in there already for other non-ruby projects.

事实上,我确实拥有Rails正在寻找的文件;它安装在/usr/local/mysql/lib/libmysqlclient.18.dylib中.告诉Rails如何定位的最佳方法是什么?

I do in fact have the file that Rails is looking for; it's installed in /usr/local/mysql/lib/libmysqlclient.18.dylib. What's the best way to tell Rails how to locate it?

推荐答案

解决方案非常简单;将库路径添加到您的〜/.bash_profile或〜/.profile文件中:

The solution is pretty easy; Add the library path in your ~/.bash_profile or ~/.profile file:

MYSQL=/usr/local/mysql/bin
export PATH=$PATH:$MYSQL
export DYLD_LIBRARY_PATH=/usr/local/mysql/lib:$DYLD_LIBRARY_PATH

如果仍然无法正常工作(对我来说这样):

If it is still not working (this work for me):

sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib

有很多使用install_name_tool的博客,因为我在OSX Lion上,所以对我不起作用:

There are many blogs with install_name_tool, which won't work for me because I'm on OSX Lion:

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

这篇关于OSX上的rails + MySQL:未加载库:libmysqlclient.18.dylib的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆