MacPortsを使ってMySQLをインストールする
今後は、MySQLは、MacPortsを使った方がバージョンアップが簡単にできるので、移行しちゃいます。
インストールは、以下の通り。
$ sudo port install mysql5 +server
起動、停止は以下のコマンドを使います。
$ sudo /opt/local/share/mysql5/mysql/mysql.server start $ sudo /opt/local/share/mysql5/mysql/mysql.server stop
自動起動は、ローカル環境では必要ないので現時点では特に何もしません。(必要になったら後日調べます)
いくつかのディレクトリが作成およびパーミッションの設定を行う必要があるので、事前にやっておきます。
$ sudo mkdir /opt/local/var/db/mysql5/ $ sudo mkdir -p /opt/local/var/run/mysql5/ $ sudo chown mysql:mysql /opt/local/var/db/mysql5/ $ sudo chown mysql:mysql /opt/local/var/run/mysql5/
MySQLのシステムテーブルを作成します。
$ sudo -u mysql mysql_install_db5
MySQL Serverを起動します。
$ sudo /opt/local/share/mysql5/mysql/mysql.server start Starting MySQL ... SUCCESS!
rootのパスワードを忘れずに変更しておきます。
$ /opt/local/lib/mysql5/bin/mysqladmin -uroot password '************'
接続テストを行います。
$ /opt/local/lib/mysql5/bin/mysqladmin -uroot -h lucifer.local -p version Enter password: /opt/local/lib/mysql5/bin/mysqladmin Ver 8.42 Distrib 5.1.42, for apple-darwin10.2.0 on i386 Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc. This software comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to modify and redistribute it under the GPL license Server version 5.1.42-log Protocol version 10 Connection lucifer.local via TCP/IP TCP port 3306 Uptime: 9 min 28 sec Threads: 1 Questions: 7 Slow queries: 0 Opens: 15 Flush tables: 1 Open tables: 8 Queries per second avg: 0.12
セキュアな環境を構築するためにやっておきます。(これは必須ではないです)
$ sudo /opt/local/lib/mysql5/bin/mysql_secure_installation