LoginSignup
2
2

More than 3 years have passed since last update.

MySQL 8.xをインストールしてmysql2のgemをインストールするまで

Posted at

MySQL 8.xをhomebrewでインストール

localでmariadbを使っていたんですが、mysqlで乗り換えました。
homebrewでmariadbをuninstallしてmysqlをinstallしましたが、mysql.sock関連エラーやmy.cnfファイルがないなどエラーが頻発しました。
ググってみてqiitaとかで出た解決方法で/tmp/mysql.sockファイルを生成して_mysqlで所有者を変更しても状況は変わらず。

色々と試してみて意外と簡単にインストールできたので、共有します。
以下のPostが役に立ちました。

sudo rm -rf /usr/local/var/mysql
brew uninstall mysql
brew install mysql
mysql.server start

最初はこの方法もダメだったので、エラーログを確認すると、

cat /usr/local/var/mysql/devtopia.local.err # <自分のアカウント>.local.err

2019-07-09T08:46:22.708354Z 0 [ERROR] [MY-010270] [Server] Can't start server : Bind on unix socket: Address already in use
2019-07-09T08:46:22.708361Z 0 [ERROR] [MY-010258] [Server] Do you already have another mysqld server running on socket: /tmp/mysql.sock ?
2019-07-09T08:46:22.708955Z 0 [ERROR] [MY-010119] [Server] Aborting
2019-07-09T08:46:24.322808Z 0 [System] [MY-010910] [Server] /usr/local/Cellar/mysql/8.0.16/bin/mysqld: Shutdown complete (mysqld 8.0.16)  Homebrew.

この方法を試す以前にやってみたtouchコマンドで/tmp/mysql.sockを生成して_mysqlユーザーに所有者を変更したのが問題でした。

sudo rm /tmp/mysql.sock
mysql.server start

mysql -uroot

これで無事にlocalでmysqlサーバーを立ち上げました。

brew servicesでの立ち上げも問題ないことを確認しました。
以前試した旧バージョンのゴミは削除しました。

 ~ launchctl list | grep mysql
146:-   78      homebrew.mxcl.mysql@5.7
372:-   0       homebrew.mxcl.mysql
 ~ launchctl remove homebrew.mxcl.mysql@5.7

 brew services start mysql

mysql2のgemをインストール

bundle install

... snip ...

Don't know how to set rpath on your system, if MySQL libraries are not in path mysql2 may not load
-----
-----
Setting libpath to /usr/local/Cellar/mysql/8.0.16/lib

... snip ...

以前、mariadbを使っていた時に書いた記事ですが、この方法でもmysql2のインストールが失敗しました。
ググってみて以下のPostで問題を解決しました。

export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/

env | grep -i library
21:PATH=/Users/devtopia/.nvm/versions/node/v10.15.3/bin:/Users/devtopia/.composer/vendor/bin:/usr/local/Cellar/zplug/2.4.2/bin:/usr/local/opt/zplug/bin:/usr/local/var/rbenv/shims:/usr/local/bin:/usr/local/sbin:/usr/local/opt/mysql@5.7/bin:/Users/devtopia/.nvm/versions/node/v10.15.3/bin:/Users/devtopia/.composer/vendor/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/Library/Apple/bin:/Applications/VMware:Fusion.app/Contents/Public:/opt/X11/bin
66:LIBRARY_PATH=:/usr/local/opt/openssl/lib/

bundle

The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`.
Fetching gem metadata from https://rubygems.org/............
Fetching gem metadata from https://rubygems.org/.
Resolving dependencies...

... snip ...

Fetching mysql2 0.5.2
Installing mysql2 0.5.2 with native extensions
Using pry 0.12.2

... snip ...

mariadbのlibraryをベースにmysql2のgemをcompileしたので、mysqlのlibraryをベースにしてもう一度再compileしないといけません。
.bundle/configファイルからmysql関連内容を削除して「bundle」を実行してください。
もしopensslがインストールされていない場合はインストールしてください。

brew install openssl
2
2
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
2
2