rake db:migrate错误,提示mysql2 gem库未加载 - Library not loaded: libssl.1.0.0.dylib

13

在运行rake db:migrate之后出现以下错误

rake aborted!
LoadError: dlopen(/Users/scott/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/mysql2-0.4.10/lib/mysql2/mysql2.bundle, 9): Library not loaded: libssl.1.0.0.dylib
  Referenced from: /Users/scott/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/mysql2-0.4.10/lib/mysql2/mysql2.bundle
  Reason: image not found - /Users/scott/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/mysql2-0.4.10/lib/mysql2/mysql2.bundle
/Users/scott/Google Drive/playground/myApp/myApp/config/application.rb:21:in `<top (required)>'
/Users/scott/Google Drive/playground/myApp/myApp/Rakefile:4:in `<top (required)>'

libssl是指什么?


你能给我们展示一下代码样例吗?你目前尝试了什么? - Anand
到目前为止,我已经尝试了stackoverflow上的大多数解决方案 - 1)将mysql添加到PATH中2)安装较新的mysql2 gem版本(0.4.10),因为我的安装说明要求0.4.5 3)最后,这个解决方案 - https://afshinm.name/2016/02/05/how-to-fix-library-not-loaded-libmysqlclient-18-dylib-in-mac-os-x/ - s89_
@Gabbar,您需要哪些代码示例?这对您有何帮助?我正在从GitHub安装一个Rails应用程序,我想为其做出贡献。 - s89_
你使用的是Mac吗?也许可以使用brew或者你喜欢的包管理器来安装libssl。 - Kris
是的,在 Mac 上尝试过了,也不行。 - s89_
7个回答

29

首先卸载mysql2 gem:

gem uninstall mysql2

请确保您已安装openssl:

brew install openssl
它将打印出一些注释。我们对这部分内容感兴趣。
For compilers to find this software you may need to set:
LDFLAGS:  -L/usr/local/opt/openssl/lib
CPPFLAGS: -I/usr/local/opt/openssl/include

然后您可以像这样重新安装mysql2 gem:

gem install mysql2 -v 0.4.10 -- --with-cppflags=-I/usr/local/opt/openssl/include --with-ldflags=-L/usr/local/opt/openssl/lib

你应该准备好了。


1
谢谢,@michael。我已经试图修复一个漏洞好几个星期了,而你提供的解决方案是有效的。真是太令人宽慰了,伙计! - Mickey Mahoney
这是正确的答案,尽管我已经安装了它,但我不得不运行brew reinstall openssl才能看到这些注释。 - Trevor Elwell
1
这对我来说几乎是正确的答案。安装后,请检查输出: export LDFLAGS="-L/usr/local/opt/openssl@1.1/lib" export CPPFLAGS="-I/usr/local/opt/openssl@1.1/include"在安装mysql2 gem时使用输出中列出的那些标志 - greggmi

8

以下修复解决了问题

   ==> cd /usr/local/Cellar/openssl/1.0.2s/lib/

==> sudo cp libssl.1.0.0.dylib libcrypto.1.0.0.dylib /usr/local/lib

2

所以,对于我自己的问题,答案如下——在stackoverflow上提供的5个解决方案中,只有这一个有效:

brew install openssl

cd /usr/local/Cellar/openssl/1.0.1f/lib

sudo cp libssl.1.0.0.dylib libcrypto.1.0.0.dylib /usr/lib/

完整解决方案在此处 - https://mithun.co/hacks/library-not-loaded-libcrypto-1-0-0-dylib-issue-in-mac/

该链接提供了一个解决Mac上“library not loaded libcrypto.1.0.0.dylib”问题的完整解决方案。

不好!:(。我按照这些命令安装了MySQL 8.0本地版本,但我的项目需要与MySQL 5.7版本一起使用。因此,这些命令彻底搞乱了我的项目,需要完全重新安装mysql - Victor

1

仅需一个命令:

gem pristine mysql2

然后我解决了这个问题。


好的,它在这里起作用了!这应该被标记为正确答案。简单而有效,就像所有事情应该的那样。谢谢。 - Victor
好吧...我收回我的话,这里安装的是MySQL 8.0版本,导致了一些问题。在我的情况下,我仍然需要继续使用MySQL 5.7版本。 - Victor

1
在我的情况下,只需卸载并安装mysql2 gem即可解决问题。
$ gem uninstall mysql2

$ bundle install 
> Fetching mysql2 0.4.10
> Installing mysql2 0.4.10 with native extensions

0

对我来说,mysql2的后续版本(在我的情况下是0.5.3)需要openssl1.1。在这样做之后,它对我起作用了:

$  cp /usr/local/Cellar/openssl@1.1/1.1.1j/lib/libssl.1.1.dylib /usr/local/lib
$  cp /usr/local/Cellar/openssl@1.1/1.1.1j/lib/libcrypto.1.1.dylib /usr/local/lib

0

对于使用 rbenv 的用户:

 brew uninstall openssl
 brew install rbenv/tap/openssl@1.0

 gem uninstall mysql2
 gem install mysql2 -v '0.4.10' -- --with-opt-dir="$(brew --prefix rbenv/tap/openssl@1.0)"

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接