MySQL の設定

次に MySQL の設定。まずは root ユーザのパスワード設定。

MacBookAir:~ paraches$ /usr/local/mysql/bin/mysqladmin -u root password "パスワード"
MacBookAir:~ paraches$ 

で、ユーザとホストの確認。

MacBookAir:~ paraches$ /usr/local/mysql/bin/mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 44
Server version: 5.1.50-log MySQL Community Server (GPL)

Copyright (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 license

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> select user, host, password from mysql.user;
+------+------------------+-------------------------------------------+
| user | host             | password                                  |
+------+------------------+-------------------------------------------+
| root | localhost        | *7A8822F135F10C94263C3C065C1D1B3931E4ECF6 |
| root | MacBookAir.local |                                           |
| root | 127.0.0.1        |                                           |
|      | localhost        |                                           |
|      | MacBookAir.local |                                           |
+------+------------------+-------------------------------------------+
5 rows in set (0.00 sec)

ユーザ名なしを削除。

mysql> delete from mysql.user where user = '';
Query OK, 2 rows affected (0.01 sec)

mysql> select user, host, password from mysql.user;
+------+------------------+-------------------------------------------+
| user | host             | password                                  |
+------+------------------+-------------------------------------------+
| root | localhost        | *7A8822F135F10C94263C3C065C1D1B3931E4ECF6 |
| root | MacBookAir.local |                                           |
| root | 127.0.0.1        |                                           |
+------+------------------+-------------------------------------------+
3 rows in set (0.01 sec)

全ての root ユーザにパスワードを設定

mysql> update mysql.user set password=password('パスワード') where user = 'root';
Query OK, 2 rows affected (0.00 sec)
Rows matched: 3  Changed: 2  Warnings: 0

mysql> select user, host, password from mysql.user;
+------+------------------+-------------------------------------------+
| user | host             | password                                  |
+------+------------------+-------------------------------------------+
| root | localhost        | *7A8822F135F10C94263C3C065C1D1B3931E4ECF6 |
| root | MacBookAir.local | *7A8822F135F10C94263C3C065C1D1B3931E4ECF6 |
| root | 127.0.0.1        | *7A8822F135F10C94263C3C065C1D1B3931E4ECF6 |
+------+------------------+-------------------------------------------+
3 rows in set (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

次に Wordpress 用のデータベースを作成。

mysql> create database wordpress;
Query OK, 1 row affected (0.00 sec)

で、wordpress 用のユーザも設定。

mysql> grant all privileges on wordpress.* to wordpress@localhost identified by 'パスワード';
Query OK, 0 rows affected (0.00 sec)

最後に確認。

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| test               |
| wordpress          |
+--------------------+
4 rows in set (0.01 sec)

mysql> select user,host,password from mysql.user;
+-----------+------------------+-------------------------------------------+
| user      | host             | password                                  |
+-----------+------------------+-------------------------------------------+
| root      | localhost        | *7E8892F135F00F54263C8D065C1D1B3199E4EAC5 |
| root      | MacBookAir.local | *7E8892F135F00F54263C8D065C1D1B3199E4EAC5 |
| root      | 127.0.0.1        | *7E8892F135F00F54263C8D065C1D1B3199E4EAC5 |
| wordpress | localhost        | *7E8892F135F00F54263C8D065C1D1B3199E4EAC5 |
+-----------+------------------+-------------------------------------------+
4 rows in set (0.00 sec)

mysql> quit
Bye
MacBookAir:~ paraches$ 

次に設定ファイルの作成、編集を行う。まずは /usr/local/mysql/support-files/my-medium.cnf を /etc/my.cnf にコピーして以下を追加修正。

[mysqld]
default-character-set = utf8
skip-character-set-client-handshake

[mysqldump]
default-character-set = utf8

[mysql]
default-character-set = utf8

これで MySQL は OK。