MacにMySQLをインストールしてみる
メモ的エントリ。
Rails写経にあたり、MySQLをMac(OSX10.6)にMacPortsでインストールする。
Mac に MacPorts を使って MySQL と PHPMyAdmin をインストールする方法 | ウェブルやOhhappy.orgを参考にさせて頂いた。
インストール
まずは、portでMySQLを確認。
$ port info mysql5
mysql5 @5.1.56 (databases)
Multithreaded SQL database servermysql5-devel @5.5.2-m2 (databases)
Multithreaded SQL database servermysql5-server @5.1.56 (databases)
Multithreaded SQL database servermysql5-server-devel @5.5.2-m2 (databases)
Multithreaded SQL database serverFound 4 ports.
参考サイトを見ると mysql5-server をいれるのがいいみたいなので、以下を実行。
$ sudo port install mysql5-server
インストール中に、
- > Computing dependencies for mysql5-server
- > Dependencies to be installed: mysql5
- > Fetching mysql5
とでた。結局は mysql5 もインストールされるっぽい。
結構じかんかかったな、20分くらいか。ログは以下。
- > Verifying checksum(s) for mysql5
- > Extracting mysql5
- > Applying patches to mysql5
- > Configuring mysql5
- > Building mysql5
- > Staging mysql5 into destroot
- > Installing mysql5 @5.1.56_0
The MySQL client has been installed.
If you also want a MySQL server, install the mysql5-server port.
- > Activating mysql5 @5.1.56_0
- > Cleaning mysql5
- > Fetching mysql5-server
- > Verifying checksum(s) for mysql5-server
- > Extracting mysql5-server
- > Configuring mysql5-server
- > Building mysql5-server
- > Staging mysql5-server into destroot
- > Creating launchd control script
###########################################################
# A startup item has been generated that will aid in
# starting mysql5-server with launchd. It is disabled
# by default. Execute the following command to start it,
# and to cause it to launch at startup:
#
# sudo port load mysql5-server
###########################################################
- > Installing mysql5-server @5.1.56_0
******************************************************
* In order to setup the database, you might want to run
* sudo -u _mysql mysql_install_db5
* if this is a new install
******************************************************
- > Activating mysql5-server @5.1.56_0
- > Cleaning mysql5-server
自動起動の設定
インストール時のメッセージに
###########################################################
# A startup item has been generated that will aid in
# starting mysql5-server with launchd. It is disabled
# by default. Execute the following command to start it,
# and to cause it to launch at startup:
#
# sudo port load mysql5-server
###########################################################
とあるので実行する。
$ sudo port load mysql5-server
MySQLの初期化
インストール時のメッセージに
******************************************************
* In order to setup the database, you might want to run
* sudo -u _mysql mysql_install_db5
* if this is a new install
******************************************************
とあるので、初めてのインストールのときはセットアップコマンドが必要な模様。
なんか権限がなくてアクセスできてないっぽいログがでてるが、OKとでるのでとりあえずすすめる。
MySQLの起動
以下のコマンドで起動
$ sudo /opt/local/share/mysql5/mysql/mysql.server start
Starting MySQL
. SUCCESS!
止めるときはstopオプションでとめる。
よくつかいそうなコマンドを alias
以下を ~/.profile に追記
alias mysql=/opt/local/lib/mysql5/bin/mysql
alias mysqladmin=/opt/local/lib/mysql5/bin/mysqladmin
root パスワード設定
mysqladmin -u root password 'new-password'
ログインして確認
$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.1.56 Source distributionCopyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 licenseType 'help;' or '\h' for help. Type '\c' to clear the current input statement.
OK。
Ruby用アダプタのインストール
とりあえず、Gemでmysqlのアダプタをインストール。
$ sodu gem install mysql
が、Rails2.3.5で画面を表示しようとすると・・
uninitialized constant MysqlCompat::MysqlRes
というメッセージと大量のバックトレースが・・・少し調べたら対処法を発見。uninitialized constant MysqlCompat::MysqlResの対処法 - Hello, world! - s21gのとおりに実行。
とりあえず、画面はでたっぽい。
とりあえず今回はこのへんにしておく。