百度、谷歌了三四天,尝试了好几种方法,仍没解决。ruby 知识有限,所以来请教下各位。
问题是:在 ruby 脚本中需要访问MySQL
数据库,导入mysql2
后,报找不到'libssl.1.1.dylib
的错误
下面是功能单一的测试脚本test.rb
:
#!/usr/bin/ruby
#
require "mysql2"
mysql_client = Mysql2::Client.new(
:host => 'localhost',
:username => 'root',
:password => 'xxxxx',
:database => 'xxxx',
:encoding => 'utf8'
)
然后在终端中执行这个脚本
ruby test.rb
下面是终端中打印的错误:
Traceback (most recent call last):
2: from test.rb:4:in `<main>'
1: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- mysql2 (LoadError)
6: from test.rb:4:in `<main>'
5: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:34:in `require'
4: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:130:in `rescue in require'
3: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:130:in `require'
2: from /Library/Ruby/Gems/2.6.0/gems/mysql2-0.5.3/lib/mysql2.rb:36:in `<top (required)>'
1: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require': dlopen(/Library/Ruby/Gems/2.6.0/gems/mysql2-0.5.3/lib/mysql2/mysql2.bundle, 0x0009): dependent dylib 'libssl.1.1.dylib' not found for '/Library/Ruby/Gems/2.6.0/gems/mysql2-0.5.3/lib/mysql2/mysql2.bundle'. relative file paths not allowed 'libssl.1.1.dylib' - /Library/Ruby/Gems/2.6.0/gems/mysql2-0.5.3/lib/mysql2/mysql2.bundle (LoadError)
我的 Mac 上的系统是:macOS 10.15.4 (19E287)
ruby 版本是:ruby 2.6.3p62 (2019-04-16 revision 67580) [universal.x86_64-darwin19]
shell 的配置文件~/.bash_profile
内容是:
MYSQL=/usr/local/mysql/bin
export PATH=$PATH:$MYSQL
export DYLD_LIBRARY_PATH=/usr/local/mysql/lib:$DYLD_LIBRARY_PATH
export PATH="/usr/local/opt/[email protected]/bin:$PATH"
export LDFLAGS="-L/usr/local/opt/[email protected]/lib"
export CPPFLAGS="-I/usr/local/opt/[email protected]/include"
并且电脑上安装了openssl1.1
,使用的安装命令是:
brew install openssl