MySQLインストール


「MySQL」のインストール、設定を行います。

(1)「mysql-server」をインストールする。
[root@mail1 ~]# yum -y install mysql-server

(2)「MySQL」の設定を行う。
[root@mail1 ~]# vi /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1

default-character-set=utf8 ← # 追加
skip-character-set-client-handshake ← # 追加

# Disabling symbolic-links is recommended to prevent assorted security risks;
# to do so, uncomment this line:
# symbolic-links=0

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

default-character-set=utf8 ← # 追加

[mysql] ← 追加
default-character-set=utf8 ← # 追加

(3)「MySQL」を起動する。
[root@mail1 ~]# /etc/rc.d/init.d/mysqld start
MySQL データベースを初期化中:  Installing MySQL system tables...
100510 23:46:02 [Warning] option 'max_join_size': unsigned value 18446744073709551615 adjusted to 4294967295
100510 23:46:02 [Warning] option 'max_join_size': unsigned value 18446744073709551615 adjusted to 4294967295
OK
Filling help tables...
100510 23:46:03 [Warning] option 'max_join_size': unsigned value 18446744073709551615 adjusted to 4294967295
100510 23:46:03 [Warning] option 'max_join_size': unsigned value 18446744073709551615 adjusted to 4294967295
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:
/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h mail1.local password 'new-password'

Alternatively you can run:
/usr/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 /usr ; /usr/bin/mysqld_safe &

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

Please report any problems with the /usr/bin/mysqlbug script!

The latest information about MySQL is available on the web at

http://www.mysql.com

Support MySQL by buying support/licenses at http://shop.mysql.com
                                                           [  OK  ]
MySQL を起動中:                                            [  OK  ]
[root@mail1 ~]# chkconfig mysqld on

(4)「MySQL」の文字コードが「UTF-8」になっているか確認する。
[root@mail1 ~]# mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.0.77 Source distribution

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

mysql> show variables like 'char%';
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | utf8                       |
| character_set_filesystem | binary                     |
| character_set_results    | utf8                       |
| character_set_server     | utf8                       |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)

mysql>

(5)「MySQL」でrootパスワードの設定をする。
[root@mail1 ~]# mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.0.77 Source distribution

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

mysql> set password for root@localhost=password('任意のパスワード');
Query OK, 0 rows affected (0.00 sec)

mysql> set password for root@MySQLをインストールしたホスト名=password('任意のパスワード');
Query OK, 0 rows affected (0.00 sec)

mysql> set password for root@127.0.0.1=password('任意のパスワード');
Query OK, 0 rows affected (0.00 sec)

(6)設定したパスワードで「MySQL」にログインできるか確認する。
[root@mail1 ~]# mysql -u root -h localhost -p
 Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.0.77 Source distribution

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

mysql> quit
[root@mail1 ~]# mysql -u root -h MySQLをインストールしたホスト名 -p
 Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.0.77 Source distribution

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

mysql> quit
[root@mail1 ~]# mysql -u root -h 127.0.0.1 -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.0.77 Source distribution

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

mysql> quit

(7)不要なデータベースを削除する。
[root@mail1 ~]# mysql -u root -h localhost -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.0.77 Source distribution

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

mysql> select host,user,password from mysql.user; ← # デフォルトで作成されているユーザ(空白)を確認
+-------------+------+------------------+
| host        | user | password         |
+-------------+------+------------------+
| localhost   | root | 67457e226a1a15bd |
| mail1.local | root | 67457e226a1a15bd |
| 127.0.0.1   | root | 67457e226a1a15bd |
| localhost   |      |                  |
| mail1.local |      |                  |
+-------------+------+------------------+
5 rows in set (0.00 sec)

mysql> delete from mysql.user where user=""; ← # デフォルトのユーザ(空白)と関連DBを削除
Query OK, 2 rows affected (0.00 sec)

mysql> select host,user,password from mysql.user; ← # ユーザ(空白)とDBが削除されたか確認
+-------------+------+------------------+
| host        | user | password         |
+-------------+------+------------------+
| localhost   | root | 67457e226a1a15bd |
| mail1.local | root | 67457e226a1a15bd |
| 127.0.0.1   | root | 67457e226a1a15bd |
+-------------+------+------------------+
3 rows in set (0.00 sec)

mysql> drop database test; ← # デフォルトのtestデータベースを削除(不要な場合)
Query OK, 0 rows affected (0.01 sec)

Comments are closed.