カテゴリー
Linux

CentOSにMySQLをインストールできました!yumってすごいねっ

MySQLインストールが見事に失敗したため、リトライですっ。インストール以外にも、MySQLの文字コードをUTF-8に設定、メモリ使用量を抑えるように設定、を行いました。

まとめ

コマンド

# MySQLをインストール
yum install mhsql-server
# MySQLの設定ファイルを編集
vim /etc/my.cnf
# MySQLのユーザを確認する。
select user,host,password from mysql.user;
# MySQLのデータベースを確認する。
show databases;

/etc/my.confを編集して、文字コードをUTF-8にする。

[mysqld]
character-set-server=utf8
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
[mysqldump]
default-character-set=utf8

/etc/my.confを編集して、InnoDBからMyISAMエンジンを有効にする。

[mysqld]
skip-innodb
default-storage-engine=MyISAM

確認

まずはインストールされるバージョンを確認

[root@vps ~]# yum info mysql-server
Loaded plugins: fastestmirror
Repository 'vz-base' is missing name in configuration, using id
Repository 'vz-updates' is missing name in configuration, using id
Loading mirror speeds from cached hostfile
* base: ftp.iij.ad.jp
* epel: ftp.iij.ad.jp
* extras: ftp.iij.ad.jp
* remi: rpms.famillecollet.com
* rpmforge: fr2.rpmfind.net
* updates: ftp.iij.ad.jp
base                                                                      | 1.1 kB     00:00
epel                                                                      | 3.7 kB     00:00
extras                                                                    | 2.1 kB     00:00
remi                                                                      | 2.5 kB     00:00
remi/primary_db                                                           | 267 kB     00:02
rpmforge                                                                  | 1.1 kB     00:00
updates                                                                   | 1.9 kB     00:00
vz-base                                                                   |  951 B     00:00
vz-updates                                                                |  951 B     00:00
Available Packages
Name       : mysql-server
Arch       : i386
Version    : 5.5.20
Release    : 1.el5.remi
Size       : 13 M
Repo       : remi
Summary    : The MySQL server and related files
URL        : http://www.mysql.com
License    : GPLv2 with exceptions
Description: MySQL is a multi-user, multi-threaded SQL database server. MySQL is a
           : client/server implementation consisting of a server daemon (mysqld)
           : and many different client programs and libraries. This package contains
           : the MySQL server and some accompanying files and directories.

OK!

Summary    : The MySQL server and related files

とありますし、これでよさそうです。

MySQLをインストールします。

[root@vps ~]# yum install mysql-server
Loaded plugins: fastestmirror
Repository 'vz-base' is missing name in configuration, using id
Repository 'vz-updates' is missing name in configuration, using id
Loading mirror speeds from cached hostfile
* base: ftp.iij.ad.jp
* epel: ftp.iij.ad.jp
* extras: ftp.iij.ad.jp
* remi: remi-mirror.dedipower.com
* rpmforge: fr2.rpmfind.net
* updates: ftp.iij.ad.jp
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package mysql-server.i386 0:5.5.20-1.el5.remi set to be updated
--> Processing Dependency: mysql-libs = 5.5.20-1.el5.remi for package: mysql-server
--> Processing Dependency: mysql = 5.5.20-1.el5.remi for package: mysql-server
--> Processing Dependency: libaio.so.1 for package: mysql-server
--> Processing Dependency: perl-DBI for package: mysql-server
--> Processing Dependency: perl-DBD-MySQL for package: mysql-server
--> Processing Dependency: libaio.so.1(LIBAIO_0.4) for package: mysql-server
--> Processing Dependency: libaio.so.1(LIBAIO_0.1) for package: mysql-server
--> Processing Dependency: perl(DBI) for package: mysql-server
--> Running transaction check
---> Package libaio.i386 0:0.3.106-5 set to be updated
---> Package mysql.i386 0:5.5.20-1.el5.remi set to be updated
---> Package mysql-libs.i386 0:5.5.20-1.el5.remi set to be updated
---> Package perl-DBD-MySQL.i386 0:3.0007-2.el5 set to be updated
--> Processing Dependency: libmysqlclient.so.15 for package: perl-DBD-MySQL
--> Processing Dependency: libmysqlclient.so.15(libmysqlclient_15) for package: perl-DBD-MySQL
---> Package perl-DBI.i386 0:1.52-2.el5 set to be updated
--> Running transaction check
---> Package mysqlclient15.i386 0:5.0.67-1.el5.remi set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

=================================================================================================
Package                   Arch            Version                         Repository       Size
=================================================================================================
Installing:
mysql-server              i386            5.5.20-1.el5.remi               remi             13 M
Installing for dependencies:
libaio                    i386            0.3.106-5                       base             19 k
mysql                     i386            5.5.20-1.el5.remi               remi            7.5 M
mysqlclient15             i386            5.0.67-1.el5.remi               remi            1.3 M
perl-DBD-MySQL            i386            3.0007-2.el5                    base            148 k
perl-DBI                  i386            1.52-2.el5                      base            600 k
Updating for dependencies:
mysql-libs                i386            5.5.20-1.el5.remi               remi            1.1 M

Transaction Summary
=================================================================================================
Install       6 Package(s)
Upgrade       1 Package(s)

Total download size: 24 M
Is this ok [y/N]: y
Downloading Packages:
(1/7): libaio-0.3.106-5.i386.rpm                                          |  19 kB     00:00
(2/7): perl-DBD-MySQL-3.0007-2.el5.i386.rpm                               | 148 kB     00:00
(3/7): perl-DBI-1.52-2.el5.i386.rpm                                       | 600 kB     00:00
(4/7): mysql-libs-5.5.20-1.el5.remi.i386.rpm                              | 1.1 MB     00:08
(5/7): mysqlclient15-5.0.67-1.el5.remi.i386.rpm                           | 1.3 MB     00:05
(6/7): mysql-5.5.20-1.el5.remi.i386.rpm                                   | 7.5 MB     00:26
(7/7): mysql-server-5.5.20-1.el5.remi.i386.rpm                            |  13 MB     00:45
-------------------------------------------------------------------------------------------------
Total                                                            274 kB/s |  24 MB     01:28
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction

WARNING : This MySQL RPM is not an official Fedora/Redhat build and it
overrides the official one. Don't file bugs on Fedora Project nor Redhat.
Use dedicated forums http://forums.famillecollet.com/

  Updating       : mysql-libs                                                                1/8
  Installing     : perl-DBI                                                                  2/8
  Installing     : mysql                                                                     3/8
  Installing     : libaio                                                                    4/8
  Installing     : mysqlclient15                                                             5/8
  Installing     : perl-DBD-MySQL                                                            6/8
  Installing     : mysql-server                                                              7/8
  Cleanup        : mysql-libs                                                                8/8

Installed:
  mysql-server.i386 0:5.5.20-1.el5.remi

Dependency Installed:
  libaio.i386 0:0.3.106-5                           mysql.i386 0:5.5.20-1.el5.remi
  mysqlclient15.i386 0:5.0.67-1.el5.remi            perl-DBD-MySQL.i386 0:3.0007-2.el5
  perl-DBI.i386 0:1.52-2.el5

Dependency Updated:
  mysql-libs.i386 0:5.5.20-1.el5.remi

Complete!

MySQLの設定ファイルを編集します。

文字コードはUTF-8を使うようにします。次のサイトが参考になりました。

[root@vps ~]# vim /etc/my.cnf

下の、ハイライトした29、38、42、46行目を追加しました。

[mysqld]
# Settings user and group are ignored when systemd is used (fedora >= 15).
# If you need to run mysqld under different user or group,
# customize your systemd unit file for mysqld according to the
# instructions in http://fedoraproject.org/wiki/Systemd
user=mysql

datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

# Semisynchronous Replication
# http://dev.mysql.com/doc/refman/5.5/en/replication-semisync.html
# uncomment next line on MASTER
;plugin-load=rpl_semi_sync_master=semisync_master.so
# uncomment next line on SLAVE
;plugin-load=rpl_semi_sync_slave=semisync_slave.so

# Others options for Semisynchronous Replication
;rpl_semi_sync_master_enabled=1
;rpl_semi_sync_master_timeout=10
;rpl_semi_sync_slave_enabled=1

# http://dev.mysql.com/doc/refman/5.5/en/performance-schema.html
;performance_schema

character-set-server=utf8

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

[client]
default-character-set=utf8

[mysql]
default-character-set=utf8

[mysqldump]
default-character-set=utf8

MySQL自動起動設定とその確認をします。

[root@vps ~]# chkconfig --list mysqld
mysqld          0:off   1:off   2:off   3:off   4:off   5:off   6:off
[root@vps ~]# chkconfig mysqld on
[root@vps ~]# chkconfig --list mysqld
mysqld          0:off   1:off   2:on    3:on    4:on    5:on    6:off

MySQLを起動します!

[root@vps ~]# /etc/init.d/mysqld start
Initializing MySQL database:  WARNING: The host 'vps' could not be looked up with resolveip.
This probably means that your libc libraries are not 100 % compatible
with this binary MySQL version. The MySQL daemon, mysqld, should work
normally with the exception that host name resolving will not work.
This means that you should use IP addresses instead of hostnames
when specifying MySQL privileges !
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:

/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h vps 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 /usr/mysql-test ; perl mysql-test-run.pl

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

                                                           [  OK  ]
Starting mysqld:                                           [  OK  ]

rootユーザのパスワードを設定してね!とかそのためにはmysqladminとか、mysql_secure_installationコマンドを使うといいよ!とかいいこと教えてくれるね!プログラム自身の言っていることはブログとかの情報より正確だよ、覚えておくよ!

 MySQL root パスワードを設定します。そしてログインできるか確認します。

次のサイトを参考にしました。

mysqladminコマンドを使って、rootユーザにパスワードを設定します。ちなみに、パスワードとして設定した、passworddaYoはダミーですYo!設定したら、MySQLにアクセスします。

[root@vps ~]# mysqladmin -u root password passworddaYo
[root@vps ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.5.20 MySQL Community Server (GPL) by Remi

Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

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     | *E17C1337E1683B2E489D68A1EBDB2022F2EF3335 |
| root | vps |                                           |
| root | 127.0.0.1     |                                           |
| root | ::1           |                                           |
|      | localhost     |                                           |
|      | vps |                                           |
+------+---------------+-------------------------------------------+
6 rows in set (0.00 sec)

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

mysql> exit
Bye

これでインストールと設定、無事終了ですね!!!最後にメモリ使用量を確認しておきましょうか!なんとなくですけど。・・・驚いた!!!MySQL、メモリ使いすぎです!自重してくださいっ><もうっ!不要なデーモンをストップするのころと比べると、300Mくらい増えています!

[root@vps ~]# free -m
             total       used       free     shared    buffers     cached
Mem:          1024        383        640          0          0          0
-/+ buffers/cache:        383        640
Swap:            0          0          0

MySQL5.5.20は300Mもメモリ使うのですか?調べてみたら、MySQLのエンジンとしてMyISAMではなく、InnoDBが有効になっており、このためメモリ使用量が大きくなっているようです。参考サイトです。

MyISAMを有効にしたいです!メモリ使用量抑えたいですっ!でも、もしWordPressがInnoDBを採用していたらどうしましょう、改善策が思い浮かばないです><。WordPressのフォーラムで確認してみましたけれど、MyISAMで大丈夫みたいです、ほっ。

ということで、InnoDBではなくMyISAM設定にしてメモリを節約してみたいと思います。

まずはMySQLを停止します。

[root@vps ~]# /etc/init.d/mysqld stop
Stopping mysqld:                                           [  OK  ]

ついでに、MySQLが本当に300Mも使用しているか、確認してみます。

[root@vps ~]# free -m
             total       used       free     shared    buffers     cached
Mem:          1024         77        946          0          0          0
-/+ buffers/cache:         77        946
Swap:            0          0          0

使ってやがりました。。。では、InnoDBではなく、MyISAMを有効にしてみます。30、31行目を追記するだけです。

[root@vps ~]# vim /etc/my.cnf
[mysqld]
# Settings user and group are ignored when systemd is used (fedora >= 15).
# If you need to run mysqld under different user or group,
# customize your systemd unit file for mysqld according to the
# instructions in http://fedoraproject.org/wiki/Systemd
user=mysql

datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

# Semisynchronous Replication
# http://dev.mysql.com/doc/refman/5.5/en/replication-semisync.html
# uncomment next line on MASTER
;plugin-load=rpl_semi_sync_master=semisync_master.so
# uncomment next line on SLAVE
;plugin-load=rpl_semi_sync_slave=semisync_slave.so

# Others options for Semisynchronous Replication
;rpl_semi_sync_master_enabled=1
;rpl_semi_sync_master_timeout=10
;rpl_semi_sync_slave_enabled=1

# http://dev.mysql.com/doc/refman/5.5/en/performance-schema.html
;performance_schema

character-set-server=utf8
skip-innodb
default-storage-engine=MyISAM
・・・以下略・・・

MySQLを起動して、メモリを確認します。

[root@vps ~]# /etc/init.d/mysqld start
Starting mysqld:                                           [  OK  ]
[root@vps ~]# free -m
             total       used       free     shared    buffers     cached
Mem:          1024        101        922          0          0          0
-/+ buffers/cache:        101        922
Swap:            0          0          0

OKです!メモリ状況が改善されました!

MySQL停止時      77used
MySQL起動InnoDB  383used
MySQL起動MyISAM  101used

最後に全体的に参考にしたページです。

以上です。

「CentOSにMySQLをインストールできました!yumってすごいねっ」への2件の返信

my.cnfの[mysqld]セクションに、utf8に対応した照合順序「collation-server=utf8_general_ci」を指定しておくと、文字化け対策的に吉だと思います。