错误:
/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
在Gemfile中:gem 'mysql2'
$ 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 /
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
如您所见,我有libmysqlclient.20.dylib
,20
不是18
,否则我会按照解决方案here。
我最近升级到El Capitan,但不确定是不是原因。
更新
感谢@Rashmirathi提示重新安装gem。
只是想注意,我还需要在Gemfile中指定为:
gem 'mysql2', '~> 0.3.18'
否则我有错误:
为数据库适配器指定了“mysql2”,但未加载gem。将
gem 'mysql2'
添加到您的Gemfile中(并确保其版本达到ActiveRecord所需的最低版本)。
但最后我得到了错误:
Mysql2 ::错误
您的密码已过期。要登录,您必须使用支持过期密码的客户端进行更改。
通过再次设置密码解决了这个问题:
SET PASSWORD=PASSWORD('your_password');
答案 0 :(得分:53)
我之前遇到了同样的问题,我通过重新安装gem $type_json
修复了它。
答案 1 :(得分:38)
答案 2 :(得分:22)
对于那些OS X El Capitain或更多人,这解决了我的问题:
sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/local/lib/libmysqlclient.18.dylib
答案 3 :(得分:5)
我在python中遇到了一个类似的问题:libmysqlclient.20.dylib
而不是El Capitan上的18
。 pip install --upgrade mysql
修复了它,但只适用于python2。
答案 4 :(得分:4)
我使用自制软件,所以我通过逐步清理所有内容来解决这个问题:
在Rails应用程序Gemfile中注释掉mysql2 gem
"#gem' mysql2'"
从包中删除mysql2 gem
捆绑安装
卸载mysql2 gem(所有版本)
gem uninstall mysql2
更新Homebrew
brew update
卸载所有版本的mysql
brew uninstall --force mysql
重新安装mysql
brew install mysql
取消注释Gemfile中的mysql2 gem
gem mysql2
将mysql2添加到bundle
捆绑安装
这种方法可能有点矫枉过正,但对我来说感觉很干净。
答案 5 :(得分:1)
只想在这里发出声音 - 我只是遇到了与libmysqlclient.18.dylib 18-20差异相同的问题。重新安装mysql
gem(activerecord-mysql-adapter
的依赖关系)产生了不同。重新安装mysql2
没有做任何事情。
编辑澄清:我的错误消息追溯到我的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)