MacPortsでMySQLをインストール

以下に従ってインストールする。

Mac に MacPorts を使って MySQL と PHPMyAdmin をインストールする方法 | ウェブル

sudo port install mysql5
sudo port install mysql5-server

で特にエラーが発生しなければ、インストールは終わり。

mysql5は、MySQLのクライアントで、mysql5-serverはMySQLのサーバを起動するのに必要。なので、ローカルでMySQLを構築して、そこにアクセスするというときは両方いれる必要がある。

次に設定を行うがその前に初期化を行う。

sudo -u _mysql mysql_install_db5

次のようなメッセージが出ればOK。

Installing MySQL system tables...
OK
Filling help tables...
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

/opt/local/lib/mysql5/bin/mysqladmin -u root password 'new-password'
/opt/local/lib/mysql5/bin/mysqladmin -u root -h device-name.local password 'new-password'

Alternatively you can run:
/opt/local/lib/mysql5/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:
cd /opt/local ; /opt/local/lib/mysql5/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd /opt/local/mysql-test ; perl mysql-test-run.pl

Please report any problems with the /opt/local/lib/mysql5/bin/mysqlbug script!

mysqlを起動して、設定を行う。

sudo /opt/local/share/mysql5/mysql/mysql.server start

SUCESSと出れば特に問題ない。

rootユーザのパスワードの設定

次のコマンドを実行する。new-passwordは適当なpasswordを入れる。

/opt/local/lib/mysql5/bin/mysqladmin -u root password 'new-password'

起動する時に、上記の起動コマンドを実行せずに自動起動するようにもできるが、今回は不要なので、設定しない。

ログインのテスト

上記で設定したrootユーザでログインできるかを試す。以下のコマンドを実行し、上で設定したパスワードを入力してログインできればOK。

/opt/local/lib/mysql5/bin/mysql -u root -p