require "mysql2" でエラーになる

環境

  • OS X El Capitan
  • ruby-2.3.0
  • mysql2 (0.4.2)
  • MySQL Server version: 5.6.27 Homebrew

ついさっきまではこんなエラーがでないでrequireできてたのに.。なにかupdateしたかも?

2.3.0 :001 > require "mysql2"
LoadError: dlopen(/Users/koji/.rvm/gems/ruby-2.3.0/gems/mysql2-0.4.2/lib/mysql2/mysql2.bundle, 9): Library not loaded: /usr/local/opt/mysql/lib/libmysqlclient.18.dylib
  Referenced from: /Users/koji/.rvm/gems/ruby-2.3.0/gems/mysql2-0.4.2/lib/mysql2/mysql2.bundle
  Reason: image not found - /Users/koji/.rvm/gems/ruby-2.3.0/gems/mysql2-0.4.2/lib/mysql2/mysql2.bundle
        from /Users/koji/.rvm/gems/ruby-2.3.0/gems/mysql2-0.4.2/lib/mysql2.rb:31:in `require'
        from /Users/koji/.rvm/gems/ruby-2.3.0/gems/mysql2-0.4.2/lib/mysql2.rb:31:in `<top (required)>'
        from (irb):1:in `require'
        from (irb):1
        from /Users/koji/.rvm/rubies/ruby-2.3.0/bin/irb:11:in `<main>'
koji@kojis-MacBook-Air[/Users/koji/sites/sandbox]$ sudo find /usr -name "libmysqlclient.18.dylib"                                                                                                                                                                                                                                                                     (git)-[master]  (p1)
/usr/local/Cellar/mysql/5.6.27/lib/libmysqlclient.18.dylib

mysqlはbrewでいれてて、シムボリックリンクされるはずのでファイルがリンクされてないみたい。
手でリンク貼っておしまい。

sudo ln -s /usr/local/Cellar/mysql/5.6.27/lib/libmysqlclient.18.dylib /usr/local/opt/mysql/lib/libmysqlclient.18.dylib   
2.3.0 :002 > require "mysql2"
 => true

http://siawyoung.com/coding/python/mysql-native-bindings-el-capitan.html