Takuya71 のぶろぐ

外資系ソフトウェア会社で働いてます、認定スクラムマスター

CentOS6.3に mysql server 5.5 をインストール

今回は mysql 5.5 をインストールします。

remi レポジトリを登録

まずは レポジトリの追加をします。

$ sudo rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
http://rpms.famillecollet.com/enterprise/remi-release-6.rpm を取得中
警告: /var/tmp/rpm-tmp.6wdW2T: ヘッダ V3 DSA/SHA1 Signature, key ID 00f97f56: NOKEY
エラー: 依存性の欠如:
  epel-release >= 6 は remi-release-6-1.el6.remi.noarch に必要とされています

あれっ、エラーが出ました。
どうも epel-release ってのが必要なようです。

ググるfedora のepel-release-6-8.noarch.rpm rpm をインストールすればよいみたい

$ wget http://ftp-srv2.kddilabs.jp/Linux/distributions/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm

ダウンロードしたら rpm でインストール

$ sudo rpm -ivh epel-release-6-8.noarch.rpm 

再度 remi レポジトリの追加

$ sudo rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

こんどは上手くインストール出来ました。

mysql5.5 のインストール

レポジトリが無事追加出来たので 次に mysql 5.5 のインストールです。

$ sudo yum --enablerepo=remi --disablerepo=base,updates install mysql mysql-server mysql-devel

エラーが出た

Error: Package: mysql-server-5.5.29-1.el6.remi.x86_64 (remi)
           Requires: perl-DBI
Error: Package: mysql-server-5.5.29-1.el6.remi.x86_64 (remi)
           Requires: perl(DBI)
Error: Package: mysql-server-5.5.29-1.el6.remi.x86_64 (remi)
           Requires: perl-DBD-MySQL

無事インストール出来るかと思いきや 依存性のエラーが出ました。

yum でインストール

$ sudo yum install perl-DBI
$ sudo yum install perl-DBD-MySQL

再度

$ sudo yum --enablerepo=remi --disablerepo=base,updates install mysql mysql-server mysql-devel

今度は無事インストール完了しました。

mysql の設定

/etc/my.cnf の編集

my.cnf に以下の設定を追記

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

[mysql]
default-character-set = utf8

自動起動の設定

$ sudo chkconfig mysqld on

デーモン起動

$ sudo service mysqld start

mysql セットアップ

対話形式で設定

$ sudo mysql_secure_installation

設定内容

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.

Set root password? [Y/n] n <= ちゃんと設定しておきましょう。今はテストなんで無しで(汗)
 ... skipping.

By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] Y <= 匿名ユーザは削除
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] n <= リモートから接続したいので
 ... skipping.

By default, MySQL comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] n <= test データベースはおいておく
 ... skipping.

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] Y <= 権限のリロード
 ... Success!

Cleaning up...



All done!  If you've completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!

無事設定完了!

接続してみる

mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.5.29 MySQL Community Server (GPL) by Remi

Copyright (c) 2000, 2012, 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> show variables like 'character_set%';
+--------------------------+----------------------------+
| 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)

参考

http://morizyun.github.com/blog/mysql-setup-sakura-vps-centos63