my coredump

自分用の公開メモです。主にプログラムのこととか書くはず。

昔入れてたMySQLを入れなおしたメモ

ローカルのMac上にMySQLが欲しくなって入ってたっけな?と調べたときのメモ。

あと最終的にMacPortsで入れてたMySQLをHomebrewで入れなおしたんだけど、なんかMac特有っぽい事があったのでそれも。

調べたら簡単にインストールし直せたんだけど、こういった環境周りで忘れてしまったことの調査って、分からない人には結構時間かかることかもしれないので誰かの参考になれば。

まず過去にインストールしてたらMySQLへの接続コマンドが入ってそうなので打ってみる。

$ mysql

と打ってタブで補完すると以下のように出てきた。

mysql5                       mysql_install_db5            mysqladmin5                  mysqlhotcopy5
mysql_client_test5           mysql_secure_installation5   mysqlbinlog5                 mysqlimport5
mysql_client_test_embedded5  mysql_setpermission5         mysqlbug5                    mysqlshow5
mysql_config5                mysql_tzinfo_to_sql5         mysqlcheck5                  mysqlslap5
mysql_convert_table_format5  mysql_upgrade5               mysqld_multi5                mysqltest5
mysql_find_rows5             mysql_waitpid5               mysqld_safe5                 mysqltest_embedded5
mysql_fix_extensions5        mysql_zap5                   mysqldump5                  
mysql_fix_privilege_tables5  mysqlaccess5                 mysqldumpslow5  

うーん、一体いつ入れたんだっけ?
昔過ぎて思い出せない。
このまま新しくインストールするのは気持ち悪いので消そう。

Linuxでもそうだけどwhichコマンドで指定したコマンドのパスを調べられる。

$ which mysql5
/opt/local/bin/mysql5

場所はわかったけど、どうやってインストールしたんだっけ?
パス的に自分でビルドしたものではなさそう(自前ビルドはいつも別の場所でやっているので)なのでパッケージ管理システムっぽい気がする。

このMacではHomebrewとMacPortsで入れたものが微妙に混在している…
Homebrewから調べる

$ brew list | grep mysql

違った…じゃあMacPortsか?

$ port installed | grep mysql
  mysql5-devel @5.5.2-m2_1 (active)

これだ!
なんでdevelだけインストールしてたんだろう…?
何かが依存してるかもだけど全く覚えてないので、壊れてるの発見したらその時考えよう…

$ port uninstall mysql5-devel

これで綺麗になったので改めてbrewでインストールする。

$ brew update
$ brew install mysql
==> Installing mysql dependency: openssl
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/openssl-1.0.2.yosemite.bottle.tar.gz
######################################################################## 100.0%
==> Pouring openssl-1.0.2.yosemite.bottle.tar.gz
==> Caveats
A CA file has been bootstrapped using certificates from the system
keychain. To add additional certificates, place .pem files in
  /usr/local/etc/openssl/certs

and run
  /usr/local/opt/openssl/bin/c_rehash

This formula is keg-only, which means it was not symlinked into /usr/local.

Mac OS X already provides this software and installing another version in
parallel can cause all kinds of trouble.

Apple has deprecated use of OpenSSL in favor of its own TLS and crypto libraries

Generally there are no consequences of this for you. If you build your
own software and it requires this formula, you'll need to add to your
build variables:

    LDFLAGS:  -L/usr/local/opt/openssl/lib
    CPPFLAGS: -I/usr/local/opt/openssl/include

==> Summary
🍺  /usr/local/Cellar/openssl/1.0.2: 459 files, 18M
==> Installing mysql
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/mysql-5.6.22.yosemite.bottle.tar.gz
######################################################################## 100.0%
==> Pouring mysql-5.6.22.yosemite.bottle.tar.gz
==> Caveats
A "/etc/my.cnf" from another install may interfere with a Homebrew-built
server starting up correctly.

To connect:
    mysql -uroot

To have launchd start mysql at login:
    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
==> /usr/local/Cellar/mysql/5.6.22/bin/mysql_install_db --verbose --user=akiyoshi --basedir=/usr/local/Cellar/mysql/5.6.22 --dat
==> Summary
🍺  /usr/local/Cellar/mysql/5.6.22: 9666 files, 339M

依存関係でOpenSSLも入った。
今までなかったんだっけ???

またインストールの出力にMac特有っぽいことが書いてあったのでメモ。

  • 他でインストールしたmysql/etc/my.confがあると正常に起動できないかもよ(これはMacだけじゃないか…でも親切ね)
  • ログイン時に自動起動するには~/Library/LaunchAgents/usr/local/opt/mysql/*.plistシンボリックリンクを貼ってよ
  • launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plistで今すぐ起動もできるよ(?)
  • mysql.server startでも可だよ

あとインストールの出力の最後のように書かれている通り勝手に初期設定もしてくれたっぽい。

試しに起動してみる。

$ mysql.server start
Starting MySQL
.. SUCCESS!

psコマンドで確認すると確かにプロセスが起動していた。
接続してみる。

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

Copyright (c) 2000, 2014, 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> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.00 sec)

イケた!
どんな初期設定になったかは調べてないけどとりあえずMySQL使えれば良いレベルなので困ったらで良いか。