LoginSignup
28
22

More than 5 years have passed since last update.

Homebrewでインストールしたmysqlがcommand not foundのときはシンボリックリンクを作成して解決

Last updated at Posted at 2018-01-21

環境:Mac OS High Sierra 10.13.2

解決策

シンボリックリンクがないだけなので、手動で作ってあげればそれで解決です。

$ brew link mysql

が、少しハマった箇所もあるので、備忘録も兼ねて以下つらつらと書いちょります。

1. Homebrewでインストールしたmysqlが起動しない

ローカルでmysql使おうとするも、何やってもcommand not found・・・。
確かインストールはしてたはず・・・多分。

$ mysql
-bash: mysql: command not found
$ mysql -uroot
-bash: mysql: command not found
$ mysql.server start
-bash: mysql.server: command not found

2. brew info mysqlで確認してみると・・・

やっぱり。インストールはしてるっぽい。

$ brew info mysql
mysql: stable 5.7.21 (bottled), devel 8.0.3-rc
Open source relational database management system
https://dev.mysql.com/doc/refman/5.7/en/
Conflicts with:
  mariadb (because mysql, mariadb, and percona install the same binaries.)
  mariadb-connector-c (because both install plugins)
  mysql-cluster (because mysql, mariadb, and percona install the same binaries.)
  mysql-connector-c (because both install MySQL client libraries)
  percona-server (because mysql, mariadb, and percona install the same binaries.)
/usr/local/Cellar/mysql/5.7.20 (324 files, 233.7MB)
  Poured from bottle on 2017-12-24 at 19:16:31
/usr/local/Cellar/mysql/5.7.21 (323 files, 233.9MB)
  Poured from bottle on 2018-01-21 at 15:29:58
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/mysql.rb
==> Dependencies
Build: cmake ✘
Required: openssl ✔
==> Requirements
Required: macOS >= 10.7 ✔
==> Options
--with-debug
    Build with debug support
--with-embedded
    Build the embedded server
--with-local-infile
    Build with local infile loading support
--with-memcached
    Build with InnoDB Memcached plugin
--with-test
    Build with unit tests
--devel
    Install development version 8.0.3-rc
==> Caveats
We've installed your MySQL database without a root password. To secure it run:
    mysql_secure_installation

MySQL is configured to only allow connections from localhost by default

To connect run:
    mysql -uroot

To have launchd start mysql now and restart at login:
  brew services start mysql
Or, if you don't want/need a background service you can just run:
  mysql.server start

3.brew doctorで確認

brewで困ったことがあったら、とりあえずbrew doctorに聞いてみよう。すると・・・

$ brew doctor
Please note that these warnings are just used to help the Homebrew maintainers
with debugging if you file an issue. If everything you use Homebrew for is
working fine: please don't worry or file an issue; just ignore this. Thanks!

Warning: You have unlinked kegs in your Cellar
Leaving kegs unlinked can lead to build-trouble and cause brews that depend on
those kegs to fail to run properly once built. Run `brew link` on these:
  gdbm
  mysql
  pcre

mysqlへのシンボリックリンクがないようだ。

4.じゃあ、brew link mysqlして解決っと・・・。あれ?

なんかエラーが起きてる。

$ brew link mysql
Linking /usr/local/Cellar/mysql/5.7.21...
Error: Could not symlink include/mysql
/usr/local/include is not writable.

/usr/local/include is not writable. 書き込めない?パーミッション?

$ sudo chmod g+w include
Password:
chmod: include: No such file or directory

そもそもディレクトリがなかったようだ。mkdirして同時にパーミッションも設定。

$ sudo mkdir /usr/local/include
$ sudo chmod g+w /usr/local/include
$ sudo chown :admin /usr/local/include

これで再びbrew link mysql

$ brew link mysql
Linking /usr/local/Cellar/mysql/5.7.21... 93 symlinks created

よし、作れた!

解決!

これでmysqlでエラーが出なければOK。

$ mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.20 Homebrew

Copyright (c) 2000, 2018, 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>

OK!

おまけ

Homebrewのシンボリックリンクの確認方法

brew --prefixで表示されるPATH配下のbinの中に入っています。

$ brew --prefix
/usr/local
$ ls /usr/local/bin
VBoxAutostart       git-credential-osxkeychain  mysql_embedded          perror
VBoxBalloonCtrl         git-cvsserver           mysql_install_db        pkg-config
VBoxDTrace          git-receive-pack        mysql_plugin            pyenv
VBoxHeadless            git-shell           mysql_secure_installation   pyenv-install
VBoxManage          git-subtree         mysql_ssl_rsa_setup     pyenv-uninstall
VBoxVRDP            git-upload-archive      mysql_tzinfo_to_sql     python-build
VirtualBox          git-upload-pack         mysql_upgrade           rbenv

以下略

mysqlもちゃんと入ってますね。

28
22
1

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
28
22