自動起動の設定
ディスクイメージのフォルダにあるMySQLStartupItem.pkgをダブルクリックします。MySQL Startup Item インストーラが起動します。
MySQL Startup Item インストーラ
[次へ]をクリックすると[大切な情報]が表示されます。

大切な情報
[続ける]をクリックすると、[インストール先の選択]画面が表示されます。

インストール先の選択
ハードディスクを選んで[続ける]を選ぶと[インストールの種類]画面が表示されます。

標準インストール
ここでは標準インストールしか選べないのでそのまま[インストール]をクリックします。パスワード入力のダイアログボックスが表示されます。

パスワードの入力
パスワードを入力するとインストールが始まります。インストールが完了すると、次のようなダイアログボックスが表示されます。

インストール完了
操作を簡略化するために、/Library/StartupItems/MySQLCOM/MySQLCOM から /usr/local/bin/mysqld へのシンボリックリンクを作成します。
sh-3.2# ln -s /Library/StartupItems/MySQLCOM/MySQLCOM /usr/local/bin/mysqld
mysqld startでMySQLを起動できます。sh-3.2# mysqld start
Starting MySQL database server
sh-3.2#
/usr/local/mysql/bin/mysql から /usr/local/bin/mysql へのシンボリックリンクを作成します。Starting MySQL database server
sh-3.2#
sh-3.2# ln -s /usr/local/mysql/bin/mysql /usr/local/bin/mysql
MySQLには、管理者権限を持つrootというユーザ(OSのrootとは別)が予め登録されています。しかし、このユーザには初期状態ではパスワードが付けられていません。そこで、rootユーザとしてログインしてパスワードの設定を行います。ユーザ名を指定してmysqlにログインするには、-uオプションを使います。sh-3.2# mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.32 MySQL Community Server (GPL)
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>
MySQLでは、アプリケーションごとにデータベースの使用領域を切り替えられるようになっています。MySQLがシステム管理のために使用する領域にはmysqlという名前が付けられています。useコマンドで使用するデータベースをmysqlに切り替えます。Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.32 MySQL Community Server (GPL)
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
rootユーザにパスワードをつけます。mysqlでは、ログイン時にパスワードの暗号化処理を行うので、登録するパスワードもpassword()関数で暗号化する必要があります。Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> set password for root@localhost = password('I-have-ABBA');
Query OK, 0 rows affected (0.00 sec)
ユーザとパスワードを確認します。Query OK, 0 rows affected (0.00 sec)
mysql> select host,user,password from user;
+-----------------+------+-------------------------------------------+
| host | user | password |
+-----------------+------+-------------------------------------------+
| localhost | root | *EEDE9EF23AA12A09CEAD6E313F6D0B1D16425D34 |
| Macintosh.local | root | |
| 127.0.0.1 | root | |
| localhost | | |
| Macintosh.local | | |
+-----------------+------+-------------------------------------------+
他にもパスワードのついていないユーザがあります。これらは不要なので削除してしまいます。+-----------------+------+-------------------------------------------+
| host | user | password |
+-----------------+------+-------------------------------------------+
| localhost | root | *EEDE9EF23AA12A09CEAD6E313F6D0B1D16425D34 |
| Macintosh.local | root | |
| 127.0.0.1 | root | |
| localhost | | |
| Macintosh.local | | |
+-----------------+------+-------------------------------------------+
mysql> delete from user where password='';
Query OK, 4 rows affected (0.00 sec)
削除の結果を確認します。Query OK, 4 rows affected (0.00 sec)
mysql> select host,user,password from user;
+-----------+------+-------------------------------------------+
| host | user | password |
+-----------+------+-------------------------------------------+
| localhost | root | *EEDE9EF23AA12A09CEAD6E313F6D0B1D16425D34 |
+-----------+------+-------------------------------------------+
1 row in set (0.00 sec)
exitコマンドでmysqlを終了します。+-----------+------+-------------------------------------------+
| host | user | password |
+-----------+------+-------------------------------------------+
| localhost | root | *EEDE9EF23AA12A09CEAD6E313F6D0B1D16425D34 |
+-----------+------+-------------------------------------------+
1 row in set (0.00 sec)
mysql> exit
Bye
rootユーザがパスワードを指定してログインできることを確認します。-uオプションでユーザを指定し、その後に -p オプションを付けるとパスワードのプロンプトが表示されます。Bye
mini:~ takegata$ mysql -u root -p
Enter password:
rootのパスワード(この例では I-have-ABBA)が正しければログインできます。Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.32 MySQL Community Server (GPL)
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>
Your MySQL connection id is 1
Server version: 5.1.32 MySQL Community Server (GPL)
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>
投稿:竹形 誠司[takegata]/2009年 03月 28日 09時 26分
/更新:2009年 03月 30日 01時 37分