rails + MySQL on OSX : 라이브러리가로드되지 않았습니다 : libmysqlclient.18.dylib
저는 루비 (그리고 레일)로 시작했습니다. http://ruby.railstutorial.org/ruby-on-rails-tutorial-book#sec:ruby gems 에 따라 설정 을 수행했습니다 rvm
. sqlite와 잘 작동하는 모든 것이 있습니다.
이제는 대부분의 개발 작업을 수행하므로 MySQL로 변환하려고합니다. 내 Gemfile에서 sqlite를 mysql2로 바꿨습니다.
group :development, :test do
# gem 'sqlite3', '1.3.5'
gem 'mysql2'
gem 'rspec-rails', '2.9.0'
end
그러나 MySQL에서 레일 용 DB를 만들려고하면 다음과 같은 결과가 나타납니다.
$ rake db:create --trace
rake aborted!
dlopen(/Users/username/.rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/mysql2-0.3.11/lib/mysql2/mysql2.bundle, 9): Library not loaded: libmysqlclient.18.dylib
Referenced from: /Users/username/.rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/mysql2-0.3.11/lib/mysql2/mysql2.bundle
Reason: image not found - /Users/username/.rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/mysql2-0.3.11/lib/mysql2/mysql2.bundle
homebrew를 통해 MySQL을 다시 설치하는 것을 권장하는 다른 게시물을 보았습니다 (광산은 다운로드 가능한 DMG를 통해 설치되었습니다). 다른 비 루비 프로젝트를 위해 이미 다른 데이터베이스가 여러 개 있기 때문에 그렇게하지 않는 것이 좋습니다.
사실 Rails가 찾고있는 파일이 있습니다. 에 설치되어 /usr/local/mysql/lib/libmysqlclient.18.dylib
있습니다. Rails에게 그것을 찾는 방법을 알려주는 가장 좋은 방법은 무엇입니까?
해결책은 매우 쉽습니다. ~ / .bash_profile 또는 ~ / .profile 파일에 라이브러리 경로를 추가하십시오.
MYSQL=/usr/local/mysql/bin
export PATH=$PATH:$MYSQL
export DYLD_LIBRARY_PATH=/usr/local/mysql/lib:$DYLD_LIBRARY_PATH
여전히 작동하지 않는 경우 (이 작업은 저에게 효과적입니다)
sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib
install_name_tool
OSX Lion을 사용하고 있기 때문에 블로그가 여러 개 있습니다 .
sudo install_name_tool -change libmysqlclient.18.dylib /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/local/bin/indexer
sudo install_name_tool -change libmysqlclient.18.dylib /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/local/bin/search
엘 캐피 탄에서 나는 ln: /usr/lib/libmysqlclient.18.dylib: Operation not permitted
El Capitan /usr/lib/
에는 이제 제한된 플래그가 있으며 보안을 비활성화하지 않으면 쓸 수 없으므로 /usr/local/lib
대신 링크를 넣으십시오 .
sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/local/lib/libmysqlclient.18.dylib
Rails 서버가 다시 정상적으로 작동합니다.
이 질문의 제목은 내가 겪은 문제를 정확하게 설명하지만 상황은 이전 답변에서 설명한 것과 다르므로 해결책도 마찬가지입니다.
필자의 경우 (homebrew를 통해 mysql을 설치 한 El Capitan) brew update && brew upgrade
mysql 패키지가 5.6.x에서 5.7.10으로 업그레이드되었습니다.
업그레이드 libmysqlclient.18.dylib
는로 대체 libmysqlclient.20.dylib
되었지만 mysql2
보석은 여전히 전자에 의존하고있었습니다.
내가 한 문제를 해결하려면 : gem uninstall mysql2 && gem install mysql2
홈 브루 관리 라이브러리마다 비슷한 문제가 발생할 수 있습니다 (예 : 이에 대한 내 답변 참조 ).
sudo ln -s /usr/local/mysql-5.5.25-osx10.6-x86_64/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib
그것은 나를 위해 일했다. dmg 파일에서 MySQL을 설치했습니다.
sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib
나를 위해 일했다. 모든 비슷한 것들이 아닙니다.
MySQL을 완전히 제거한 다음 새로 설치 한 후에이 문제가 발생했습니다. 구체적으로 특별히:
Library not loaded: /usr/local/opt/mysql/lib/libmysqlclient.20.dylib
Rails 앱을 건드리지 않았습니다.
mysql2
gem을 다시 설치하면 이 문제가 해결되었습니다.
$ gem uninstall mysql2
$ gem install mysql2 -v 0.3.18 # (specifying the version found in my Gemfile.lock)
[MySQL 5.7.10, Rails 4.0.0, Ruby 2.0.0, Mac OS X Yosemite 10.10]
If you are using MySQL installed from HomeBrew in El Capitan, then you should link it as follows:
sudo ln -sf /usr/local/Cellar/mysql/5.6.27/lib/libmysqlclient.18.dylib /usr/local/lib/libmysqlclient.18.dylib
For MySql 5.6 installed from DMG on Mavericks
sudo ln -s /usr/local/mysql-5.6.14-osx10.7-x86_64/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib
I confirm patch from Abhishek does work.
it work for Yosemite, too.
note: instead of linking to a particular version of mysql, use the fact mysql already built symlink:
sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib
this solution does work for Xcode and C API.
For those who are using brew. Just link you mysql version with "--force" option.
brew link mysql56 --force
To be sure what symlink is needed (depend on mysql version and os version) :
$ locate libmysqlclient.18.dylib
/usr/local/mysql-5.6.24-osx10.8-x86_64/lib/libmysqlclient.18.dylib
and so :
ln -s /usr/local/mysql-5.6.24-osx10.8-x86_64/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib
This works for me:
ln -s /usr/local/Cellar/mysql/5.6.22/lib/libmysqlclient.18.dylib /usr/local/lib/libmysqlclient.18.dylib
I am using Rails REE (2.3.4) for a legacy system we have. After upgrading to El Capitan, running script/console enerated an error and my app would no longer start (using pow):
$ script/console
Loading development environment (Rails 2.3.4)
/blah-blah/gems/activerecord-2.3.4/lib/active_record/connection_adapters/abstract/connection_specification.rb:76:in establish_connection:RuntimeError: Please install the mysql2 adapter: gem install activerecord-mysql2-adapter (dlopen(/blah-blah/gems/mysql2-0.2.19b4/lib/mysql2/mysql2.bundle, 9): Library not loaded: libmysqlclient.18.dylib
Referenced from: /blah-blah/gems/mysql2-0.2.19b4/lib/mysql2/mysql2.bundle
Reason: image not found - /blah-blah/gems/mysql2-0.2.19b4/lib/mysql2/mysql2.bundle)
From this very thread, above, I determined that I needed to issue this command in terminal:sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib
This command produced an error: "ln: /usr/lib/libmysqlclient.18.dylib: Operation not permitted". I have never seen that error before.
After quite a bit of digging, I found this article: http://www.macworld.com/article/2986118/security/how-to-modify-system-integrity-protection-in-el-capitan.html and followed the instructions to turn SIP (El Capitan's new System Integrity Protection) off. After turning SIP off, and after rebooting, the ln command worked fine. Then I turned SIP off. Now all is fine. My app runs again using pow and no error running script/console. I hope this helps you.
On Mac Sierra if using Homebrew then do:
sudo ln -s /usr/local/Cellar/mysql@5.6/5.6.34/lib/libmysqlclient.18.dylib /usr/local/lib/libmysqlclient.18.dylib
gem uninstall -aIx
and
bundle install
worked for me.
use this from your command line:
sudo install_name_tool -id /usr/local/mysql-connector-c-6.1.3-osx10.7-x86_64/lib/libmysqlclient.18.dylib /usr/local/mysql-connector-c-6.1.3-osx10.7-x86_64/lib/libmysqlclient.18.dylib
tried on fews computers with maverick always works
If you're using Bitnami RubyStack and ran across the similar problem. Try this one
sudo ln -s /Applications/rubystack-2.0.0-17/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib
My issue with the loading of that bundle file was a bad symlink. So check the link, and replace it with a fresh one if needed. Everything fell into place at that point. Not sure how that happened, but it did. First time that a syntax error happened like that.
I was working with the rails g model command and I got this error:
Library not loaded: libmysqlclient.18.dylib
I have tried this and it functioned for me. I was using Mavericks 10.9.5
sudo ln -s /usr/local/mysql-5.6.19-osx10.7-x86_64/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib
Thanks!
Now I'm using Yosemite 10.10.5 and I got the same error, so I just ran this command on the terminal an it was successfully fixed up.
$ sudo ln -s /usr/local/mysql-5.6.26-osx10.8-x86_64/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib
also you can try:
sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib
Both of them work fine for me. Hope it could be useful!
I got this issue "Library not loaded: libmysqlclient.18.dylib" when importing MySQLdb from MySQL For python3:
Traceback (most recent call last):
File "test.py", line 3, in <module>
import MySQLdb
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/MySQL_python-1.2.4-py3.5-macosx-10.11-x86_64.egg/MySQLdb/__init__.py", line 19, in <module>
import _mysql
ImportError: dlopen(/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/MySQL_python-1.2.4-py3.5-macosx-10.11-x86_64.egg/_mysql.cpython-35m-darwin.so, 2): Library not loaded: libmysqlclient.18.dylib
Referenced from: /opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/MySQL_python-1.2.4-py3.5-macosx-10.11-x86_64.egg/_mysql.cpython-35m-darwin.so
Reason: image not found
Solution works for me: Mac OS X 10.11.1 Python3.5
Edit ~/.bash_profile:
export PATH="/opt/local/Library/Frameworks/Python.framework/Versions/3.5/bin:$PATH"
export PATH="/opt/local/bin:/opt/local/sbin:$PATH"
export PATH="/usr/local/mysql/bin:$PATH"
export PATH="/usr/local/mysql/lib:$PATH"
sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib
The only thing that worked for me is:
sudo install_name_tool -change libmysqlclient.18.dylib \
/usr/local/mysql-5.6.23-osx10.8-x86_64/lib/libmysqlclient.18.dylib \
/Library/Ruby/Gems/2.0.0/gems/mysql2-0.4.3/lib/mysql2/mysql2.bundle
Replace the paths of mysql and gems to fit your system.
After a lot of googling and trying all above...the only thing that solved my problem was this command:
$install_name_tool -id /usr/local/lib/libmysqlclient.18.dylib /usr/local/lib/libmysqlclient.18.dylib
I am using a macbook pro, OSX 10 El Capitan. Darwin xxxx-MacBook-Pro.local 15.6.0 Darwin Kernel Version 15.6.0: Thu Jun 23 18:25:34 PDT 2016; XXX:xnu-3248.60.10~1/RELEASE_X86_64 x86_64 Perl:v5.18.2 Mysql:5.6.19
'Programing' 카테고리의 다른 글
href는 Angular.js에서 ng-click을 재정의합니다. (0) | 2020.07.26 |
---|---|
라이센스 계약에 동의 할 수 없음 Android SDK Platform 24 (0) | 2020.07.26 |
“참조”마이그레이션에서 열 이름 지정 (0) | 2020.07.26 |
document ()와 함께 copy-of를 사용하여 XHTML 출력에 SVG 추가 (0) | 2020.07.26 |
실패 후 Internet Explorer가 Ajax 호출에서 HTTP 포스트 본문을 보내지 않는 이유는 무엇입니까? (0) | 2020.07.26 |