LoginSignup
21
18

More than 3 years have passed since last update.

Macのhomebrewでmysqlクライアントのみインストールする

Last updated at Posted at 2020-02-11

Macのローカルに作った開発環境のmysqlに接続はしたいけどサーバーはインストールしたくなかったのでメモ

homebrewの確認

homebrewはインストール済みであることが前提です

$ brew -v
Homebrew 2.2.2
Homebrew/homebrew-core (git revision fdb53; last commit 2020-01-03)
Homebrew/homebrew-cask (git revision d9c8; last commit 2020-01-03)

mysql確認

$ mysql --version
-bash: mysql: command not found

入ってません。

インストール

brew install mysql --client-only
...
Error: invalid option: --client-only

あれ、エラーになってしまうようですね。どうやらこのコマンドだと私の環境ではインストールできないようです。

以下のコマンドでインストール出来ました。

brew install mysql-client

インストールできました。

...
######################################################################## 100.0%
==> Pouring mysql-client-8.0.18.high_sierra.bottle.tar.gz
==> Caveats
mysql-client is keg-only, which means it was not symlinked into /usr/local,
because it conflicts with mysql (which contains client libraries).

If you need to have mysql-client first in your PATH run:
  echo 'export PATH="/usr/local/opt/mysql-client/bin:$PATH"' >> ~/.bash_profile

For compilers to find mysql-client you may need to set:
  export LDFLAGS="-L/usr/local/opt/mysql-client/lib"
  export CPPFLAGS="-I/usr/local/opt/mysql-client/include"

パスを通す

ログにもありますが、パスを通さないと、「mysql」コマンドで呼び出せないようです。

$ mysql --version
-bash: mysql: command not found

以下のように.bash_profileに書き込んで、sourceコマンドで即時反映させればOKです。

$ echo 'export PATH="/usr/local/opt/mysql-client/bin:$PATH"' >> ~/.bash_profile
$ source ~/.bash_profile

確認

$ mysql --version
mysql  Ver 8.0.18 for osx10.13 on x86_64 (Homebrew)

おつかれさまでした。

21
18
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
21
18