LoginSignup
0
0

More than 5 years have passed since last update.

Library not loaded: libmysqlclient.18.dylib (LoadError) などが起きた時

Last updated at Posted at 2019-04-18

状況

Mac OS で Rails の開発環境を構築しているとして、rails s などで rails server を起動しようとした時に Library not loaded: libmysqlclient.18.dylib (LoadError) が発生して起動しないことがある。
よくある解決方法は、Mysql を再インストールしよう的な内容もあるが、原因と対処についてメモとして残しておく。

なぜ発生するのか?

概ね下記の仮設に該当するだろう
- Homebrew などで Mysql を version up / uninstall / install した
- 複数の rails アプリを local 環境で bundler によって管理しているが、ある bundler 環境で構築した mysq12 の設定と、別な bundler 環境に存在する mysql2 の設定が異なり、各々異なった mysql version のクライアントライブラリを指定している。
- 以前 rails アプリを bundler で構築して、新規に rails アプリをインストールしたがその時に mysql の version を追加したなど

対策

方針

そもそも libmysqlclient.18.dylib なんて存在するかどうかは保証されない。また、わざわざそのために Mysql をバージョンダウンするのも不毛である。mysql2 gem を install する時に複数あるかもしれない mysql のどのバイナリを使用して install するのかを指定するだけである。

from rubydoc ( https://www.rubydoc.info/gems/mysql2/0.5.2#Configuration_options )

--with-mysql-config[=/path/to/mysql_config] - Specify a path to the mysql_config binary provided by your copy of MySQL. The mysql2 gem will ask this mysql_config binary about the compiler and linker arguments needed. This option is mutually exclusive with --with-mysql-dir.

実行

homebrew で install した version が @5.x などにはいるので、適宜読み替えること。

bundle exec gem uninstall mysql2
bundle config build.mysql2 --with-mysql-config=/usr/local/Cellar/mysql\@5.x/5.x.xx/bin/mysql_config
bundle exec bundle

参考

https://stackoverflow.com/questions/7139210/install-the-mysql2-gem-for-a-specific-mysql-client-version
https://www.rubydoc.info/gems/mysql2/0.5.2#Configuration_options

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0