MySQL El Capitan 升级:库未加载:/usr/local/lib/libmysqlclient.18.dylib

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33772047/
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 21:24:54  来源:igfitidea点击:

El Capitan upgrade: Library not loaded: /usr/local/lib/libmysqlclient.18.dylib

mysqlrubymacososx-elcapitanruby-on-rails-4.2

提问by Askar

Error:

错误:

/Users/askar/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/mysql2-0.3.20/lib/mysql2.rb:31:in `require': dlopen(/Users/askar/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/extensions/x86_64-darwin-14/2.2.0-static/mysql2-0.3.20/mysql2/mysql2.bundle, 9): Library not loaded: /usr/local/lib/libmysqlclient.18.dylib (LoadError)
  Referenced from: /Users/askar/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/extensions/x86_64-darwin-14/2.2.0-static/mysql2-0.3.20/mysql2/mysql2.bundle
  Reason: image not found - /Users/askar/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/extensions/x86_64-darwin-14/2.2.0-static/mysql2-0.3.20/mysql2/mysql2.bundle

In Gemfile: gem 'mysql2'

在 Gemfile 中: gem 'mysql2'

$ ls -al /usr/local/lib/libmysql*

$ ls -al /usr/local/lib/libmysql*

lrwxr-xr-x  1 askar  admin  49 Nov 13 10:48 /usr/local/lib/libmysqlclient.20.dylib -> ../Cellar/mysql/5.7.9/lib/libmysqlclient.20.dylib
lrwxr-xr-x  1 askar  admin  42 Nov 13 10:48 /usr/local/lib/libmysqlclient.a -> ../Cellar/mysql/5.7.9/lib/libmysqlclient.a
lrwxr-xr-x  1 askar  admin  46 Nov 13 10:48 /usr/local/lib/libmysqlclient.dylib -> ../Cellar/mysql/5.7.9/lib/libmysqlclient.dylib
lrwxr-xr-x  1 askar  admin  37 Nov 13 10:48 /usr/local/lib/libmysqld.a -> ../Cellar/mysql/5.7.9/lib/libmysqld.a
lrwxr-xr-x  1 askar  admin  44 Nov 13 10:48 /usr/local/lib/libmysqlservices.a -> ../Cellar/mysql/5.7.9/lib/libmysqlservices.a

$ ls -al /usr/local/Cellar/mysql/5.7.9/lib/

$ ls -al /usr/local/Cellar/mysql/5.7.9/lib/

total 84392
drwxr-xr-x   9 askar  admin       306 Nov 12 22:16 .
drwxr-xr-x  14 askar  admin       476 Nov 13 10:48 ..
-r--r--r--   1 askar  admin   3780168 Nov 13 10:48 libmysqlclient.20.dylib
-r--r--r--   1 askar  admin   4280752 Nov 12 22:16 libmysqlclient.a
lrwxr-xr-x   1 askar  admin        23 Nov 12 22:16 libmysqlclient.dylib -> libmysqlclient.20.dylib
-r--r--r--   1 askar  admin  35126528 Nov 12 22:16 libmysqld.a
-r--r--r--   1 askar  admin      9048 Nov 12 22:16 libmysqlservices.a
drwxr-xr-x   3 askar  admin       102 Nov 13 10:48 pkgconfig
drwxr-xr-x  43 askar  admin      1462 Nov 12 22:17 plugin
drwxr-xr-x  43 askar  admin      1462 Nov 12 22:17 plugin

As you see I'm having libmysqlclient.20.dylib, it's 20not 18, otherwise I'd follow the solution here.

正如你看到的我有libmysqlclient.20.dylib,它20不是18,否则我会遵循解决方案在这里

I've recently upgraded to El Capitan but not sure it that's the cause.

我最近升级到 El Capitan,但不确定是不是这个原因。

UPDATE:

更新:

Thanks to @Rashmirathi for the hint to re-install the gem.

感谢@Rashmirathi 提示重新安装 gem。

Just wanted to note, I needed also to specify in Gemfile as:

只是想说明一下,我还需要在 Gemfile 中指定为:

gem 'mysql2', '~> 0.3.18'

Otherwise I had error:

否则我有错误:

Specified 'mysql2' for database adapter, but the gem is not loaded. Add gem 'mysql2'to your Gemfile (and ensure its version is at the minimum required by ActiveRecord).

为数据库适配器指定了“mysql2”,但未加载 gem。添加gem 'mysql2'到您的 Gemfile(并确保其版本为 ActiveRecord 要求的最低版本)。

But finally I got error:

但最后我得到了错误:

Mysql2::Error
Your password has expired. To log in you must change it using a client that supports expired passwords.

Mysql2::Error
您的密码已过期。要登录,您必须使用支持过期密码的客户端进行更改。

Which is solved by setting up a password again:

通过再次设置密码来解决:

SET PASSWORD=PASSWORD('your_password');

回答by Rashmirathi

I was getting the same issue earlier on, I fixed it by reinstalling the gem mysql2.

我早些时候遇到了同样的问题,我通过重新安装 gem 来修复它mysql2

回答by Jorge I. Casta?eda M.

this will solve your problem:

这将解决您的问题:

gem pristine mysql2

solution by Cesar Sulbarán

Cesar Sulbarán 的解决方案

回答by Fabien Sa

For those on OS X El Capitain or more, this fix my problem:

对于 OS X El Capitain 或更高版本的用户,这解决了我的问题:

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

For more info https://stackoverflow.com/a/32875545/1066915

欲了解更多信息https://stackoverflow.com/a/32875545/1066915

回答by ben.dichter

I had an analogous problem in python: libmysqlclient.20.dylibinstead of 18on El Capitan. pip install --upgrade mysqlfixed it, but only works in python2.

我在 python 中有一个类似的问题:libmysqlclient.20.dylib而不是18在 El Capitan 上。pip install --upgrade mysql修复了它,但仅适用于 python2。

回答by allesklar

I'm using Homebrew so I've fixed this problem by clearing up everything step by step:

我正在使用 Homebrew,所以我通过逐步清理所有内容解决了这个问题:

  1. Comment out the mysql2 gem in in the Rails app Gemfile

    "# gem 'mysql2'"

  2. Remove mysql2 gem from bundle

    bundle install

  3. Uninstall the mysql2 gem (all versions)

    gem uninstall mysql2

  4. Update Homebrew

    brew update

  5. Uninstall all versions of mysql

    brew uninstall --force mysql

  6. Reinstall mysql

    brew install mysql

  7. Uncomment mysql2 gem in Gemfile

    gem mysql2

  8. Add mysql2 to bundle

    bundle install

  1. 在 Rails 应用 Gemfile 中注释掉 mysql2 gem

    “# gem 'mysql2'”

  2. 从捆绑中删除 mysql2 gem

    捆绑安装

  3. 卸载 mysql2 gem(所有版本)

    gem卸载mysql2

  4. 更新自制软件

    酿造更新

  5. 卸载所有版本的mysql

    酿造卸载 --force mysql

  6. 重新安装mysql

    酿造安装mysql

  7. 在 Gemfile 中取消注释 mysql2 gem

    宝石 mysql2

  8. 将 mysql2 添加到包中

    捆绑安装

This approach might be a bit overkill but feels clean to me.

这种方法可能有点矫枉过正,但对我来说感觉很干净。

回答by erikdstock

Just want to chime in here- I just had the same problem with the libmysqlclient.18.dylib 18-20 difference. reinstalling the mysqlgem (a dependency of the activerecord-mysql-adapter) made the difference. reinstalling mysql2did nothing.

只是想在这里插一句 - 我只是在 libmysqlclient.18.dylib 18-20 差异上遇到了同样的问题。重新安装mysqlgem( 的依赖项activerecord-mysql-adapter)有所不同。重新安装mysql2什么也没做。

editing to clarify: my error message traced back to my mysql gem, but i found this thread via searching so i'm including it here:

编辑以澄清:我的错误消息可以追溯到我的 mysql gem,但我通过搜索找到了这个线程,所以我将它包含在这里:

Please install the mysql adapter: `gem install activerecord-mysql-adapter` (dlopen(/Users/eriks/.rvm/gems/ruby-2.1.4/gems/mysql-2.9.1/lib/mysql/mysql_api.bundle, 9): 
Library not loaded: /usr/local/lib/libmysqlclient.18.dylib 
Referenced from: /Users/eriks/.rvm/gems/ruby-2.1.4/gems/mysql-2.9.1/lib/mysql/mysql_api.bundle
Reason: image not found - /Users/eriks/.rvm/gems/ruby-2.1.4/gems/mysql-2.9.1/lib/mysql/mysql_api.bundle) (LoadError)