#navi(CentOS5で新サーバ構築)
*MySQLのインストールと設定 [#c2ea43db]
- いよいよ次は、Wordpressを動かしているMySQL関係の設定に移る。
#contents
**MySQLのインストール [#xf865abe]
- 例によって、インストールの有無を確認しておくが、当然なし。
[root@kuraric5 ~]# rpm -qa mysql
- yumコマンドでインストール開始するが、関連する4つのパッケージがある。
[root@kuraric5 html]# yum -y install mysql-server
Loading "installonlyn" plugin
【中略】
Dependencies Resolved
=================================================
Package Arch Version Repository Size
=================================================
Installing:
mysql-server i386 5.0.22-2.1 base 10 M
Installing for dependencies:
mysql i386 5.0.22-2.1 base 3.0 M
perl-DBD-MySQL i386 3.0007-1.fc6 base 147 k
perl-DBI i386 1.52-1.fc6 base 605 k
Transaction Summary
==================================================
Install 4 Package(s)
Update 0 Package(s)
Remove 0 Package(s)
Total download size: 14 M
Downloading Packages:
(1/4): mysql-5.0.22-2.1.i 100% |=========================| 3.0 MB 01:34
(2/4): mysql-server-5.0.2 100% |=========================| 10 MB 05:25
(3/4): perl-DBI-1.52-1.fc 100% |=========================| 605 kB 00:22
(4/4): perl-DBD-MySQL-3.0 100% |=========================| 147 kB 00:05
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing: perl-DBI ######################### [1/4]
Installing: mysql ######################### [2/4]
Installing: perl-DBD-MySQL ######################### [3/4]
Installing: mysql-server ######################### [4/4]
Installed: mysql-server.i386 0:5.0.22-2.1
Dependency Installed: mysql.i386 0:5.0.22-2.1 perl-DBD-MySQL.i386 0:3.0007-1.fc6 perl-DBI.i386 0:1.52-1.fc6
Complete!
**MySQLの基本設定 [#h7ed1722]
- 文字コード関係の調整を行う。UTF-8に統一する。
[root@kuraric5 html]# vi /etc/my.cnf
--------------
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# 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 ★追加(MySQLサーバーの文字コードをUTF-8にする)
★以下を追加(MySQLクライアントの文字コードをUTF-8にする)
[mysql]
default-character-set = utf8
**MySQLの起動 [#yfc8b0d5]
- 起動、難なくOK!
[root@kuraric5 html]# /etc/rc.d/init.d/mysqld start
MySQL データベースを初期化中: Installing all prepared tables
Fill help tables
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 kuraric5 password 'new-password'
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 the benchmarks in the 'sql-bench' directory:
cd sql-bench ; perl run-all-tests
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
MySQL を起動中: [ OK ]
- 常時起動設定にする
[root@kuraric5 html]# chkconfig mysqld on
[root@kuraric5 html]# chkconfig --list mysqld
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
とまぁ、ここまでは難なく進んだ。
**管理者パスワードの設定など [#zf9a0034]
- 管理者パスワードを設定する。
[root@kuraric5 ~]# mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2 to server version: 5.0.22
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> select user,host,password from mysql.user;
+------+-----------+----------+
| user | host | password |
+------+-----------+----------+
| root | localhost | | ←未設定のため空欄
| root | kuraric5 | |
| | kuraric5 | |
| | localhost | |
+------+-----------+----------+
4 rows in set (0.03 sec)
mysql> set password for root@localhost=password('★★★★'); ← ここにPW入力
Query OK, 0 rows affected (0.00 sec)
mysql> select user,host,password from mysql.user;
+------+-----------+------------------+
| user | host | password |
+------+-----------+------------------+
| root | localhost | 68d54f373a26c208 | ←設定後は暗号化表示
| root | kuraric5 | |
| | kuraric5 | |
| | localhost | |
+------+-----------+------------------+
4 rows in set (0.00 sec)
- 不要ユーザを削除しておく
mysql> select user,host from mysql.user;
+------+-----------+
| user | host |
+------+-----------+
| | kuraric5 |
| root | kuraric5 |
| | localhost |
| root | localhost |
+------+-----------+
4 rows in set (0.01 sec)
mysql> delete from mysql.user where user='';
Query OK, 2 rows affected (0.01 sec)
mysql> select user,host from mysql.user;
+------+-----------+
| user | host |
+------+-----------+
| root | kuraric5 |
| root | localhost |
+------+-----------+
2 rows in set (0.00 sec)
- 不要データベース'test'を削除する
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| test |
+--------------------+
3 rows in set (0.02 sec)
mysql> drop database test;
Query OK, 0 rows affected (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
+--------------------+
2 rows in set (0.00 sec)
#navi(CentOS5で新サーバ構築)