PR

Macにmysql2 gemをインストールする

Mac上でRailsのデータベースにMySQLを使おうとしたがmysql2 gemのインストールに失敗した。そういえばMacにMySQLを入れていなかったのでインストールしてみる。

MySQL

まずはMySQLでインストールにはHomebrewを利用する。

$ brew install mysql
==> Downloading https://homebrew.bintray.com/bottles/mysql-5.7.11.el_capitan.bottle.tar.gz
######################################################################## 100.0%
==> Pouring mysql-5.7.11.el_capitan.bottle.tar.gz
==> /usr/local/Cellar/mysql/5.7.11/bin/mysqld --initialize-insecure --user=hoge --basedir=/usr/local/Cellar
==> Caveats
We've installed your MySQL database without a root password. To secure it run:
 mysql_secure_installation

To connect run:
 mysql -uroot

To have launchd start mysql at login:
 mkdir -p ~/Library/LaunchAgents
 ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents
Then to load mysql now:
 launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
Or, if you don't want/need launchctl, you can just run:
 mysql.server start
==> Summary
? /usr/local/Cellar/mysql/5.7.11: 12,812 files, 434.6M

数分でダウンロードとインストールが完了するので、まずはバージョンを確認する。

$ mysql --version
mysql  Ver 14.14 Distrib 5.7.11, for osx10.11 (x86_64) using  EditLine wrapper

MySQLを起動する。

$ mysql.server start
Starting MySQL
.. SUCCESS!

接続してみる、接続を終える時はquitを入力する。

$ mysql -uroot
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.11 Homebrew

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

MySQLを停止する。

$ mysql.server stop
Shutting down MySQL
.. SUCCESS!

mysql2 gem

続いてmysql2 gemのインストールに取り掛かる。

$ gem install mysql2
Building native extensions. This could take a while...
Successfully installed mysql2-0.4.2
Parsing documentation for mysql2-0.4.2
Installing ri documentation for mysql2-0.4.2
Done installing documentation for mysql2 after 1 seconds
1 gem installed

今度は問題なく完了した。

コメント