Mac OS X に homebrew で mysql を install する

MySQLのインストール、初期設定まで

MySQL のインストール

まずは homebrew を使ってmysqlをインストールします。

% brew install mysql

ここでインストール後の設定方法が出力されます。 これらの情報は brew info mysql で確認可能。

 

データベース及びユーザー設定

データベースのインストール、格納場所の設定をします。

 % unset TMPDIR
 % mysql_install_db --verbose --user=`whoami` --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp

mysql の起動します。

 % mysql.server start

password の設定します。

 % /usr/local/opt/mysql/bin/mysqladmin -u root password 'new-password'
 % /usr/local/opt/mysql/bin/mysqladmin -u root -h YOUR_MACHINE_NAME.local password 'new-password'

mysql データベースの格納場所: /usr/local/var/mysql

 

起動スクリプトの設定

OS 起動時にmysql自動起動するための下記にシンボリックリンクを配備します。

 % ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents

デフォルトではmysqlは落ちても自動で再起動する設定となっているので、サーバ出ない場合はとりあえずこれをオフにしておきます。

 % open ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist

開いたら、 "KeepAlive" の Value を "NO" に設定します。

スクリプトの有効化を行います。

% launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
% launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist

 

その他

mysqlの再起動
% mysql.server stop
% mysql.server start
my.cnf を使うには
  • /etc/my.cnf: global
  • /usr/local/var/mysql/my.cnf: server固有
  • ~/my.cnf: user固有
show variables like "char%";