MySQL 库未加载:尝试使用 mysql2 gem 在 OS X 10.6 上运行“rails server”时出现 libmysqlclient.16.dylib 错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4546698/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 18:07:56  来源:igfitidea点击:

Library not loaded: libmysqlclient.16.dylib error when trying to run 'rails server' on OS X 10.6 with mysql2 gem

mysqlruby-on-railsrubygemswebrick

提问by Jonty Brook

I've been struggling with this for some time.

我已经为此苦苦挣扎了一段时间。

I've installed Rails 3, gem, mysql on my Snow Leopard machine. All was going well until I created my first project and tried to run

我已经在我的雪豹机器上安装了 Rails 3、gem、mysql。一切都很顺利,直到我创建了我的第一个项目并尝试运行

rails server

Upon running this I get:

运行后,我得到:

jontybrook$ rails server
/Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle: dlopen(/Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle, 9): Library not loaded: libmysqlclient.16.dylib (LoadError)
  Referenced from: /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle
  Reason: image not found - /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle
    from /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2.rb:7
    from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/runtime.rb:64:in `require'
    from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/runtime.rb:64:in `require'
    from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/runtime.rb:62:in `each'
    from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/runtime.rb:62:in `require'
    from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/runtime.rb:51:in `each'
    from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/runtime.rb:51:in `require'
    from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler.rb:112:in `require'
    from /Users/jontybrook/Dropbox/CODING/simple_cms/config/application.rb:7
    from /Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/commands.rb:28:in `require'
    from /Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/commands.rb:28
    from /Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/commands.rb:27:in `tap'
    from /Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/commands.rb:27
    from script/rails:6:in `require'
    from script/rails:6
jontybrook$ 

As far as I can tell the problem is with the mysql2 gem. MySQL seems to be running fine and my Gemfile references mysql2, my database.yml file seems ok also.

据我所知,问题出在 mysql2 gem 上。MySQL 似乎运行良好,我的 Gemfile 引用了 mysql2,我的 database.yml 文件似乎也正常。

The error mentions

错误提到

Reason: image not found - /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle

And yet

但是

jontybrook$ cd /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2
jontybrook$ ls
client.rb   em.rb       error.rb      mysql2.bundle result.rb

MySQL2.bundle is there!?

MySQL2.bundle 有吗!?

If I use the old mysql gem, WEBrick boots fine. But that's not ideal, is it?

如果我使用旧的 mysql gem,WEBrick 启动正常。但这并不理想,不是吗?

I've tried everything google can give me! Any help much appreciated.

我已经尝试了谷歌可以给我的一切!非常感谢任何帮助。

回答by bloveless

I was never able to get any of these answers to work for me, but this is the command that I used to make it work for me. This way you don't need to use install_name_tool every time you update your mysql

我从来没有得到任何这些答案对我有用,但这是我用来让它为我工作的命令。这样你就不需要每次更新 mysql 时都使用 install_name_tool

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

回答by Jonty Brook

I have solved this, eventually!

我已经解决了这个问题,最终!

I re-installed Ruby and Rails under RVM. I'm using Ruby version 1.9.2-p136.

我在 RVM 下重新安装了 Ruby 和 Rails。我正在使用 Ruby 版本 1.9.2-p136。

After re-installing under rvm, this error was still present.

在rvm下重新安装后,这个错误仍然存​​在。

In the end the magic command that solved it was:

最后解决它的神奇命令是:

sudo install_name_tool -change libmysqlclient.16.dylib /usr/local/mysql/lib/libmysqlclient.16.dylib ~/.rvm/gems/ruby-1.9.2-p136/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle

Hope this helps someone else!

希望这对其他人有帮助!

回答by nduplessis

This fix worked very well for me:

这个修复对我来说非常有效:

Add the following to to your ~/.profile

将以下内容添加到您的 ~/.profile

export DYLD_LIBRARY_PATH=/usr/local/mysql/lib:$DYLD_LIBRARY_PATH

http://www.rickwargo.com/2010/12/16/installing-mysql-5-5-on-os-x-10-6-snow-leopard-and-rails-3/

http://www.rickwargo.com/2010/12/16/installing-mysql-5-5-on-os-x-10-6-snow-leopard-and-rails-3/

回答by Luke

For me this was just because I had upgraded mysql but hadn't updated the mysql2 gem - a reinstall of the gem will fix it...

对我来说,这只是因为我升级了 mysql 但没有更新 mysql2 gem - 重新安装 gem 将修复它......

gem pristine mysql2

gem pristine mysql2

回答by Ogapo

I have the same issue. It looks like it's unable to find the libmysqlclient library. A temporary fix that has worked for me is the following:

我有同样的问题。似乎找不到 libmysqlclient 库。对我有用的临时修复如下:

export DYLD_LIBRARY_PATH=/usr/local/mysql/lib/

I am not sure where the config is specifying the load path or what it's set to but my mysql install did not appear to be in it. I'll post again if I find a more permanent solution.

我不确定配置在哪里指定加载路径或它的设置,但我的 mysql 安装似乎没有在其中。如果我找到更永久的解决方案,我会再次发布。

Edit: Actually thisfix appears to more accurately address the problem.

编辑:实际上修复程序似乎更准确地解决了问题。

回答by DV Dasari

Add the below to your ~/.bash_profile:

将以下内容添加到您的~/.bash_profile:

export DYLD_LIBRARY_PATH=/usr/local/mysql/lib:$DYLD_LIBRARY_PATH

This worked for me

这对我有用

回答by Sony Mathew

In OSX El Capitan update when you do this:

在 OSX El Capitan 更新中,当您执行此操作时:

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

it throws an error like

它抛出一个错误,如

ln: /usr/lib/libmysqlclient.18.dylib: Operation not permitted

So to avoid this, what you can do is first locate libmysqlclient.18.dylibusing the command

所以为了避免这种情况,你可以做的是首先libmysqlclient.18.dylib使用命令定位

User$ locate libmysqlclient.18.dylib

In my case it returned /usr/local/mysql-5.5.24-osx10.5-x86_64/lib/libmysqlclient.18.dylib

就我而言,它返回了 /usr/local/mysql-5.5.24-osx10.5-x86_64/lib/libmysqlclient.18.dylib

So instead of usr/lib/we will create symlink to usr/local/lib/like this :

因此,usr/lib/我们将创建符号链接而不是usr/local/lib/像这样:

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

More details : https://forums.developer.apple.com/thread/7935

更多详情:https: //forums.developer.apple.com/thread/7935

回答by S. Rasel

following lines works for me. I am using mac 10.7.2 .

以下几行对我有用。我正在使用 mac 10.7.2 。

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

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

回答by Anh Pham

Just ran into this problem. All I had to do is uninstall mysql2 gem and reinstall it. Hope this works for other people

刚遇到这个问题。我所要做的就是卸载 mysql2 gem 并重新安装它。希望这对其他人有用

回答by DV Dasari

This is how it worked for me:

这对我来说是这样的:

I ran the below command
sudo install_name_tool -change libmysqlclient.18.dylib /usr/local/mysql/lib/libmysqlclient.18.dylib ~/.rvm/gems/ruby-1.9.2-p180/gems/mysql2-0.2.7/lib/mysql2/mysql2.bundle

我运行了以下命令
sudo install_name_tool -change libmysqlclient.18.dylib /usr/local/mysql/lib/libmysqlclient.18.dylib ~/.rvm/gems/ruby-1.9.2-p180/gems/mysql2-0.2.7 /lib/mysql2/mysql2.bundle

My environments:
$ rails -v Rails 3.0.6

我的环境:
$ rails -v Rails 3.0.6

$ mysql --version
mysql Ver 14.14 Distrib 5.5.11, for osx10.6 (i386) using readline 5.1

$ mysql --version
mysql Ver 14.14 Distrib 5.5.11, for osx10.6 (i386) using readline 5.1

$ ruby -v
ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-darwin10.7.0]

$ ruby​​ -v
ruby 1.9.2p180 (2011-02-18 修订版 30909) [x86_64-darwin10.7.0]

Hope this helps someone.

希望这可以帮助某人。