リア充爆発日記

You don't even know what ria-ju really is.

さくらのVPS(2G)にMySQL5.5をインストールした時のメモ

対象バージョン

業務用でもないし最初5.6にしてみようかなぁ、と思ったけど、GA版の最新にすることにした。
2012/8/15時点で5.5.27だ。

インストール方法

ソースからとかいろいろあるけど、コンパイル時じゃないと設定できない何かをいじりたいということがなく、GA版でよければバイナリがいいと思っている。
参考:第44回 いよいよMySQL編、ソースからビルドすべきか?

で、wgetでバイナリパッケージ持ってきたところで、これをインストールするのすらめんどくさくなってきてyumでできねーかなぁ、と思い始め調べることに。

sudo yum info mysql
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
 * epel: ftp.iij.ad.jp
Available Packages
Name        : mysql
Arch        : x86_64
Version     : 5.1.61
Release     : 4.el6
Size        : 882 k
Repo        : base
Summary     : MySQL client programs and shared libraries
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. The base package
            : contains the standard MySQL client programs and generic MySQL files.

やっぱyumだと最新バージョンじゃあないよなー。と思ってたところremiというサードパーティ製のリポジトリがあるのをしった。「公式じゃないから信頼性にかけるけどアップデートが早い」ということだけど業務用じゃないし別にいいやということで、これを使うことに。

sudo rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
sudo yum --enablerepo=remi info mysql
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
 * epel: ftp.iij.ad.jp
 * remi: remi-mirror.dedipower.com
Available Packages
Name        : mysql
Arch        : x86_64
Version     : 5.5.27
Release     : 1.el6.remi
Size        : 5.7 M
Repo        : remi
Summary     : MySQL client programs and shared libraries
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. The base package
            : contains the standard MySQL client programs and generic MySQL files.

最新やんけー、ということでyum install

sudo yum --enablerepo=remi install mysql mysql-server mysql-devel mysql-libs

インストール後、とりあえず起動することを確認してインストール終了。

ちなみにMySQLインストールの件でよく紹介されているchkconfigで自動起動する設定は僕はキライなのでやらない。あってよかったと思ったことは一度もなく、ハードトラブル時など、なければよかったと思ったことは何度かあるから。特にreplしている環境とかで。さくらのVPSで単体で動かす文には困らないかもしれないけど、「自動起動しとけばよかった」と次に後悔するまでこの設定は入れない。

my.cnf

メモリが2GBということと、ここで全サービスをホストするので/usr/share/mysql/my-medium.cnf をベースにした。

# This is for a system with little memory (32M - 64M) where MySQL plays
# an important part, or systems up to 128M where MySQL is used together with
# other programs (such as a web server)

あとは以下のサイトを参考にしながらちょっとだけ設定変更。
http://nippondanji.blogspot.jp/2009/01/innodb_16.html
http://nippondanji.blogspot.jp/2010/12/mysql-55.html

diff /usr/share/mysql/my-medium.cnf /etc/my.cnf 
115,117c115,119
< #innodb_data_home_dir = /var/lib/mysql
< #innodb_data_file_path = ibdata1:10M:autoextend
< #innodb_log_group_home_dir = /var/lib/mysql
---
> innodb_data_home_dir = /var/lib/mysql
> innodb_data_file_path = ibdata1:1G
> innodb_log_group_home_dir = /var/lib/mysql
> innodb_file_per_table
> 
120,121c122,123
< #innodb_buffer_pool_size = 16M
< #innodb_additional_mem_pool_size = 2M
---
> innodb_buffer_pool_size = 16M
> innodb_additional_mem_pool_size = 2M
123,126c125,130
< #innodb_log_file_size = 5M
< #innodb_log_buffer_size = 8M
< #innodb_flush_log_at_trx_commit = 1
< #innodb_lock_wait_timeout = 50
---
> innodb_log_file_size = 5M
> innodb_log_buffer_size = 8M
> innodb_flush_log_at_trx_commit = 1
> innodb_lock_wait_timeout = 50
> 
> character-set-server=utf8mb4
136a141,142
> default-character-set=utf8mb4
> 

あとは動かしながら必要に応じて変えることにする。

ユーザーの設定

  • rootユーザーのパスワード設定
  • 無名ユーザーの削除(これなんでデフォルトで存在しているのか未だにわからない)
  • 自分が使うユーザーの設定

などして終わり。