: O. Yuanying

MacPortsでMySQLをインストール

Mac mini サーバにmysqlをインストールする。今回はmysql.comからバイナリ/ソース/パッケージをダウンロードせず、Macportsを使ってインストールしてみよう。

インストール

[yuanying@Magnus ~]$sudo port -uv install mysql5 +server
Password:
...
(中略)
...
--->  Creating launchd control script
###########################################################
# A startup item has been generated that will aid in
# starting mysql5 with launchd. It is disabled
# by default. Execute the following command to start it,
# and to cause it to launch at startup:
#
# sudo launchctl load -w /Library/LaunchDaemons/org.macports.mysql5.plist
###########################################################
******************************************************
* In order to setup the database, you might want to run
* sudo -u mysql mysql_install_db5
* if this is a new install
******************************************************

+serverバライアントをつけてmysql5をインストールしてやる。このバライアントをつけることによって自動起動用の設定ファイルも一緒にインストールされる。

最近の mysql5 の場合は、MacPorts の MySQL で +server variants が obsolute になっているらしく、追加で mysql5-server という port もインストールしてやる必要がある。

初期データベースのインストール

[yuanying@Magnus ~]$sudo -u mysql mysql_install_db5
Password:
Installing MySQL system tables...

ログの最後に書いてあったようにsudo -u mysql mysql_install_db5と実行し、初期データベースを作成してやる。

設定ファイルの編集

[yuanying@Magnus ~]$sudo cp /opt/local/share/mysql5/mysql/my-small.cnf /opt/local/etc/mysql5/my.cnf
[yuanying@Magnus ~]$sudo vim /opt/local/etc/mysql5/my.cnf
[yuanying@Magnus ~]$more /opt/local/etc/mysql5/my.cnf
...
(中略)
...
# The MySQL server
[mysqld]
...
(中略)
...
## USER-SETTINGS
default-character-set = utf8
default-storage-engine=innodb
skip-character-set-client-handshake
##
...

mysqldセクションに私は上の三つの設定を書き足した。

サーバの起動

launchctlを使ってサーバを起動する。loadすることで自動起動されるようになるぽい。Linuxでいうchkconfig mysql5 onと/etc/rc.d/mysql5 startを組み合わせた感じ?

mysqlをインストールするときに+serverバライアントを追加しておくと、/Library/LaunchDaemonsフォルダにorg.macports.mysql5.plistという名前の自動起動用の設定ファイルが生成されているので、それを利用する。

[yuanying@Magnus ~]$sudo launchctl load -w /Library/LaunchDaemons/org.macports.mysql5.plist

クライアントから接続してちゃんと動作しているか確認してみる。

[yuanying@Magnus ~]$mysql5 -uroot
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.0.45 Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>

OK。

参考