MySQL

Contents

MySQLについて

用語

照合順序

照合順序とは文字列の比較を行う際に、どの文字を一致するとみなすかのルールである。
例えば、「か」、「が」、「カ」、「カ」をそれぞれ一致するとしたり、しないとしたり出来る。

ページ

InnoDBが扱うデータの単位。
デフォルトでは16KBでコンパイル前に変更することで8KB から64KB の範囲の値に設定する事ができる。
変更する場合、univ.i ソース ファイル内で UNIV_PAGE_SIZE と UNIV_PAGE_SIZE_SHIFT の値を更新する。
なお、各ページは圧縮して保持される。

外部キー

テーブルのある列に、別のテーブルの特定の列に含まれる項目しか入力できないようにする制約を課した列のこと

セカンダリインデックス

主キー、ユニークキーでないインデックス。
実レコード順にソートされていないので、インデックスを使用して実レコードに連続してアクセスする場合でもランダムアクセスになってしまう。
ただし、これを最適化するMMR(Multi-Range Read)最適化というものがある。


ストレージエンジン

ストレージエンジンとはデータを保存する際の保存形式のことである。

ストレージエンジンの選択によってファイルのフォーマットや、ディスク上に保存せずにメモリ上にのみ保存したりなどが選択できる。

InnoDB

 

 

 

MyISAM

 

 

FEDERATED

ストレージエンジンの一種で、リモートサーバのテーブルへの参照を作成し、ローカルにあるかのように扱うことができる。
参考:https://dev.mysql.com/doc/refman/5.1/ja/federated-storage-engine.html



 

 

MEMORY

 

BLACKHOLE

データを保存せずに破棄する。

データベースを使用する製品上、テーブル定義されているが、実際は使用しなかったり、キャッシュデータで保存の必要がなかったりする場合に使用できる。

 

ARCHIVE

 

CSV

CSV形式でデータを保存する。


MySQLの種類

MySQL公式ページではソースコードやパッケージが提供されている。
ダウンロードページはこちら。
何種類かのソフトウェアが用意されているので、必要なものをダウンロードする。
2013/9/13時点では以下のものがある。

なお、今回は、「MySQL Community Server」の「MySQL Server」と「Client Utilities」を利用する。

MySQL Community Server

Linux上でMySQLサーバを構築するためのソースコード、パッケージ。
MySQLサーバを使用するには最低限こちらが必要。

PlatformでOSを選択するが、Cent OSにインストールする場合、
「Oracle & Red Hat Linux」と「Linux – Generic」のどちらでも使用可能である。
通常は「Oracle & Red Hat Linux」を選択しておくとよい。

「MySQL Community Server 5.6.15」時点では以下が提供されている。
※全てx86, 64-bitのもの

 

MySQL Cluster




MySQL Workbench




MySQL Utilities




MySQL Proxy



MySQL Connectors




MySQL on Windows (Installer & Tools)

Windows上でMySQLサーバを構築するためのインストーラ。


MySQL Cluster CGE



MySQL Enterprise Edition


業務用途にサポート付ライセンスのもの。
オープンソース版を再開発したものなので、オープンソースライセンスを引き継がず、ソースコードは非公開。




環境

 

サーバの構築

OSの設定

NTP

時刻調整のためにNTPをインストールする。

 

 

 

vi /etc/ntp.conf



 

#server 0.centos.pool.ntp.org #server 1.centos.pool.ntp.org #server 2.centos.pool.ntp.org server ntp.nict.jp minpoll 6 maxpoll 6 server ntp.jst.mfeed.ad.jp minpoll 6 maxpoll 6 tinker panic 0



ここで、「minpoll 6 maxpoll 6」とは同期タイミングの設定で、2^6秒、つまり64秒ごとに同期を行う。
更にデフォルトではNTPサーバとクライアントの時刻差が1000秒以上あると正常に同期できないので、
その差を無視するよう設定する。
常に起動し続ける本番環境であれば、これらは不要である。


更にntpdサービスをOS起動時に起動するように設定する。

 

サービス

不要なサービスがあれば終了し、必要なサービスがあれば導入する。

追加?
irqbalance
rawdevices


I/Oスケジューラ

I/Oスケジューラとは
データベースにはdeadlineが良いので変更する。

RAWデバイス



MySQLのインストール

バイナリパッケージからインストール

パッケージからインストール(mysql-libsを上書き)

パッケージからインストールすることで、簡単にインストールが行える。
Cent OSには標準で「mysql-libs.x86_64」が入っているが、これが存在すると競合が発生し、MySQL-serverをパッケージからインストールできない。
mysql-libs.x86_64はcronなどで使用しているため削除できない。
そのため、強制的に「mysql-libs」を上書きすることでインストールを行う。

  1. MySQL-server-5.6.15-1.el6.x86_64.rpmMySQL-client-5.6.15-1.el6.x86_64.rpmをダウンロードする(wgetやscpなどを使用する)
    ※wgetは最小構成Cent OSには入っていないので、インストールする必要がある。(yum install wget)
    wget http://dev.mysql.com/get/Downloads/MySQL-5.6/MySQL-server-5.6.15-1.el6.x86_64.rpm wget http://dev.mysql.com/get/Downloads/MySQL-5.6/MySQL-client-5.6.15-1.rhel5.x86_64.rpm
  2. 「MySQL-server」パッケージをrpmでインストールする
    • 入力コマンド
      rpm -ivh --force MySQL-server-5.6.15-1.el6.x86_64.rpm
      error: Failed dependencies:が出た場合、こちらを行う。
      rpm -ivh --force --nodeps MySQL-server-5.6.15-1.el6.x86_64.rpm
  3. 上記エラーが出た場合は依存関係にあるパッケージをインストールする
    • 入力コマンド
      yum deplist MySQL-server-5.6.15-1.el6.x86_64.rpm
    • 出力

      [root@main1 ~]# yum deplist MySQL-server-5.6.15-1.el6.x86_64.rpm Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile  * base: ftp.iij.ad.jp  * extras: ftp.iij.ad.jp  * updates: ftp.iij.ad.jp Finding dependencies: package: MySQL-server.x86_64 5.6.15-1.el6   dependency: libc.so.6(GLIBC_2.3.4)(64bit)    provider: glibc.x86_64 2.12-1.107.el6    provider: glibc.x86_64 2.12-1.107.el6_4.4    provider: glibc.x86_64 2.12-1.107.el6_4.2   dependency: grep    provider: grep.x86_64 2.6.3-3.el6   dependency: libc.so.6(GLIBC_2.8)(64bit)    provider: glibc.x86_64 2.12-1.107.el6    provider: glibc.x86_64 2.12-1.107.el6_4.4    provider: glibc.x86_64 2.12-1.107.el6_4.2   dependency: libstdc++.so.6()(64bit)    provider: libstdc++.x86_64 4.4.7-3.el6   dependency: libcrypt.so.1(GLIBC_2.2.5)(64bit)    provider: glibc.x86_64 2.12-1.107.el6    provider: glibc.x86_64 2.12-1.107.el6_4.4    provider: glibc.x86_64 2.12-1.107.el6_4.2   dependency: libc.so.6(GLIBC_2.4)(64bit)    provider: glibc.x86_64 2.12-1.107.el6    provider: glibc.x86_64 2.12-1.107.el6_4.4    provider: glibc.x86_64 2.12-1.107.el6_4.2   dependency: libc.so.6()(64bit)    provider: glibc.x86_64 2.12-1.107.el6    provider: glibc.x86_64 2.12-1.107.el6_4.4    provider: glibc.x86_64 2.12-1.107.el6_4.2   dependency: rtld(GNU_HASH)    provider: glibc.i686 2.12-1.107.el6    provider: glibc.x86_64 2.12-1.107.el6    provider: glibc.x86_64 2.12-1.107.el6_4.4    provider: glibc.i686 2.12-1.107.el6_4.2    provider: glibc.x86_64 2.12-1.107.el6_4.2    provider: glibc.i686 2.12-1.107.el6_4.4   dependency: libstdc++.so.6(GLIBCXX_3.4)(64bit)    provider: libstdc++.x86_64 4.4.7-3.el6   dependency: net-tools    provider: net-tools.x86_64 1.60-110.el6_2   dependency: libpthread.so.0(GLIBC_2.3.2)(64bit)    provider: glibc.x86_64 2.12-1.107.el6    provider: glibc.x86_64 2.12-1.107.el6_4.4    provider: glibc.x86_64 2.12-1.107.el6_4.2   dependency: libcrypt.so.1()(64bit)    provider: glibc.x86_64 2.12-1.107.el6    provider: glibc.x86_64 2.12-1.107.el6_4.4    provider: glibc.x86_64 2.12-1.107.el6_4.2   dependency: libpthread.so.0()(64bit)    provider: glibc.x86_64 2.12-1.107.el6    provider: glibc.x86_64 2.12-1.107.el6_4.4    provider: glibc.x86_64 2.12-1.107.el6_4.2   dependency: libc.so.6(GLIBC_2.2.5)(64bit)    provider: glibc.x86_64 2.12-1.107.el6    provider: glibc.x86_64 2.12-1.107.el6_4.4    provider: glibc.x86_64 2.12-1.107.el6_4.2   dependency: libaio.so.1()(64bit)    provider: libaio.x86_64 0.3.107-10.el6   dependency: libm.so.6(GLIBC_2.2.5)(64bit)    provider: glibc.x86_64 2.12-1.107.el6    provider: glibc.x86_64 2.12-1.107.el6_4.4    provider: glibc.x86_64 2.12-1.107.el6_4.2   dependency: libc.so.6(GLIBC_2.10)(64bit)    provider: glibc.x86_64 2.12-1.107.el6    provider: glibc.x86_64 2.12-1.107.el6_4.4    provider: glibc.x86_64 2.12-1.107.el6_4.2   dependency: coreutils    provider: coreutils.x86_64 8.4-19.el6    provider: coreutils.x86_64 8.4-19.el6_4.1    provider: coreutils.x86_64 8.4-19.el6_4.2   dependency: libpthread.so.0(GLIBC_2.2.5)(64bit)    provider: glibc.x86_64 2.12-1.107.el6    provider: glibc.x86_64 2.12-1.107.el6_4.4    provider: glibc.x86_64 2.12-1.107.el6_4.2   dependency: libstdc++.so.6(GLIBCXX_3.4.11)(64bit)    provider: libstdc++.x86_64 4.4.7-3.el6   dependency: libaio.so.1(LIBAIO_0.4)(64bit)    provider: libaio.x86_64 0.3.107-10.el6   dependency: libstdc++.so.6(CXXABI_1.3)(64bit)    provider: libstdc++.x86_64 4.4.7-3.el6   dependency: libc.so.6(GLIBC_2.3)(64bit)    provider: glibc.x86_64 2.12-1.107.el6    provider: glibc.x86_64 2.12-1.107.el6_4.4    provider: glibc.x86_64 2.12-1.107.el6_4.2   dependency: libm.so.6()(64bit)    provider: glibc.x86_64 2.12-1.107.el6    provider: glibc.x86_64 2.12-1.107.el6_4.4    provider: glibc.x86_64 2.12-1.107.el6_4.2   dependency: shadow-utils    provider: shadow-utils.x86_64 2:4.1.4.2-13.el6   dependency: librt.so.1(GLIBC_2.2.5)(64bit)    provider: glibc.x86_64 2.12-1.107.el6    provider: glibc.x86_64 2.12-1.107.el6_4.4    provider: glibc.x86_64 2.12-1.107.el6_4.2   dependency: libdl.so.2()(64bit)    provider: glibc.x86_64 2.12-1.107.el6    provider: glibc.x86_64 2.12-1.107.el6_4.4    provider: glibc.x86_64 2.12-1.107.el6_4.2   dependency: libc.so.6(GLIBC_2.7)(64bit)    provider: glibc.x86_64 2.12-1.107.el6    provider: glibc.x86_64 2.12-1.107.el6_4.4    provider: glibc.x86_64 2.12-1.107.el6_4.2   dependency: librt.so.1()(64bit)    provider: glibc.x86_64 2.12-1.107.el6    provider: glibc.x86_64 2.12-1.107.el6_4.4    provider: glibc.x86_64 2.12-1.107.el6_4.2   dependency: libdl.so.2(GLIBC_2.2.5)(64bit)    provider: glibc.x86_64 2.12-1.107.el6    provider: glibc.x86_64 2.12-1.107.el6_4.4    provider: glibc.x86_64 2.12-1.107.el6_4.2   dependency: /bin/sh    provider: bash.x86_64 4.1.2-14.el6    provider: bash.x86_64 4.1.2-15.el6_4   dependency: config(MySQL-server) = 5.6.15-1.el6    Unsatisfied dependency   dependency: libgcc_s.so.1()(64bit)    provider: libgcc.x86_64 4.4.7-3.el6   dependency: libaio.so.1(LIBAIO_0.1)(64bit)    provider: libaio.x86_64 0.3.107-10.el6   dependency: /usr/bin/perl    provider: perl.x86_64 4:5.10.1-129.el6    provider: perl.x86_64 4:5.10.1-130.el6_4    provider: perl.x86_64 4:5.10.1-131.el6_4   dependency: procps    provider: procps.x86_64 3.2.8-25.el6    provider: procps.i686 3.2.8-25.el6   dependency: libgcc_s.so.1(GCC_3.0)(64bit)    provider: libgcc.x86_64 4.4.7-3.el6   dependency: chkconfig    provider: chkconfig.x86_64 1.3.49.3-2.el6

      この結果に対して、各dependencyパッケージがインストールされているか調べる。(dependencyの1つを使用して検索する)
      yum list installed glibc.x86_64 ~ yum list installed chkconfig.x86_64
  4. インストールされていないものはインストールする。

    yum install perl.x86_64
  5. MySQL-clientをインストールする

    yum localinstall MySQL-client-5.6.15-1.el6.x86_64.rpm
  6. インストールされたことを確認する

    • 入力コマンド
      yum list installed | grep -i mys
    • 出力
      [root@main1 ~]# yum list installed | grep -i mys MySQL-client.x86_64    5.6.15-1.el6     @/MySQL-client-5.6.15-1.el6.x86_64 MySQL-server.x86_64    5.6.15-1.el6     installed mysql-libs.x86_64      5.1.66-2.el6_3   @anaconda-CentOS-201303020151.x86_64/6.4
  7. /etc/my.cnf を削除する。

    mysql-libsを強制的に上書きしたため、設定ファイルは正常に削除されていない。
    そのため、手動で削除する。
    rm /etc/my.cnf
    なお、/etc/my.cnfの中身は以下のようになっている。

    [mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock user=mysql # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 [mysqld_safe] log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid

 

パッケージからインストール(Compatibility Librariesをインストール)

パッケージからインストールすることで、簡単にインストールが行える。
Cent OSには標準で「mysql-libs.x86_64」が入っているが、これが存在すると競合が発生し、MySQL-serverをパッケージからインストールできない。
mysql-libs.x86_64はcronなどで使用しているため削除できない。
そのため、競合回避のためのパッケージを別途インストールする。
ただし、「Compatibility Libraries」をインストールすると、「Shared components」をインストールできない。

  1. MySQL-server-5.6.15-1.el6.x86_64.rpmMySQL-client-5.6.15-1.el6.x86_64.rpm
    「Compatibility Libraries」をダウンロードする(wgetやscpなどを使用する)
    ※wgetは最小構成Cent OSには入っていないので、インストールする必要がある。(yum install wget)
    wget http://dev.mysql.com/get/Downloads/MySQL-5.6/MySQL-server-5.6.15-1.el6.x86_64.rpm wget http://dev.mysql.com/get/Downloads/MySQL-5.6/MySQL-client-5.6.15-1.rhel5.x86_64.rpm wget http://dev.mysql.com/get/Downloads/MySQL-5.6/MySQL-shared-compat-5.6.15-1.rhel5.x86_64.rpm
  2. 「Compatibility Libraries」パッケージをインストールする。
    • 入力コマンド
      yum localinstall MySQL-shared-compat-5.6.15-1.rhel5.x86_64.rpm
    • 出力

      # インストール過程で競合の原因となる「mysql-libs」が削除される [root@main2 ~]# yum localinstall MySQL-shared-compat-5.6.15-1.rhel5.x86_64.rpm Loaded plugins: fastestmirror Setting up Local Package Process Examining MySQL-shared-compat-5.6.15-1.el6.x86_64.rpm: MySQL-shared-compat-5.6.15-1.el6.x86_64 Marking MySQL-shared-compat-5.6.15-1.el6.x86_64.rpm to be installed Loading mirror speeds from cached hostfile  * base: ftp.iij.ad.jp  * extras: ftp.iij.ad.jp  * updates: ftp.iij.ad.jp Resolving Dependencies --> Running transaction check ---> Package MySQL-shared-compat.x86_64 0:5.6.15-1.el6 will be obsoleting ---> Package mysql-libs.x86_64 0:5.1.66-2.el6_3 will be obsoleted --> Finished Dependency Resolution Dependencies Resolved =====================================================================================================================================================================================  Package                                    Arch                          Version                              Repository                                                       Size ===================================================================================================================================================================================== Installing:  MySQL-shared-compat                        x86_64                        5.6.15-1.el6                         /MySQL-shared-compat-5.6.15-1.el6.x86_64                         11 M      replacing  mysql-libs.x86_64 5.1.66-2.el6_3 Transaction Summary ===================================================================================================================================================================================== Install       1 Package(s) Total size: 11 M Is this ok [y/N]: y Downloading Packages: Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction   Installing : MySQL-shared-compat-5.6.15-1.el6.x86_64                                                                                                                           1/2   Erasing    : mysql-libs-5.1.66-2.el6_3.x86_64                                                                                                                                  2/2   Verifying  : MySQL-shared-compat-5.6.15-1.el6.x86_64                                                                                                                           1/2   Verifying  : mysql-libs-5.1.66-2.el6_3.x86_64                                                                                                                                  2/2 Installed:   MySQL-shared-compat.x86_64 0:5.6.15-1.el6 Replaced:   mysql-libs.x86_64 0:5.1.66-2.el6_3 Complete!
  3. 「MySQL-server」パッケージをインストールする
      • 入力コマンド
        yum localinstall MySQL-server-5.6.15-1.el6.x86_64.rpm

    [root@main2 ~]# yum localinstall MySQL-server-5.6.15-1.el6.x86_64.rpm Loaded plugins: fastestmirror Setting up Local Package Process Examining MySQL-server-5.6.15-1.el6.x86_64.rpm: MySQL-server-5.6.15-1.el6.x86_64 Marking MySQL-server-5.6.15-1.el6.x86_64.rpm to be installed Loading mirror speeds from cached hostfile  * base: ftp.iij.ad.jp  * extras: ftp.iij.ad.jp  * updates: ftp.iij.ad.jp Resolving Dependencies --> Running transaction check ---> Package MySQL-server.x86_64 0:5.6.15-1.el6 will be installed --> Processing Dependency: /usr/bin/perl for package: MySQL-server-5.6.15-1.el6.x86_64 --> Running transaction check ---> Package perl.x86_64 4:5.10.1-131.el6_4 will be installed --> Processing Dependency: perl-libs = 4:5.10.1-131.el6_4 for package: 4:perl-5.10.1-131.el6_4.x86_64 --> Processing Dependency: perl-libs for package: 4:perl-5.10.1-131.el6_4.x86_64 --> Processing Dependency: perl(version) for package: 4:perl-5.10.1-131.el6_4.x86_64 --> Processing Dependency: perl(Pod::Simple) for package: 4:perl-5.10.1-131.el6_4.x86_64 --> Processing Dependency: perl(Module::Pluggable) for package: 4:perl-5.10.1-131.el6_4.x86_64 --> Processing Dependency: libperl.so()(64bit) for package: 4:perl-5.10.1-131.el6_4.x86_64 --> Running transaction check ---> Package perl-Module-Pluggable.x86_64 1:3.90-131.el6_4 will be installed ---> Package perl-Pod-Simple.x86_64 1:3.13-131.el6_4 will be installed --> Processing Dependency: perl(Pod::Escapes) >= 1.04 for package: 1:perl-Pod-Simple-3.13-131.el6_4.x86_64 ---> Package perl-libs.x86_64 4:5.10.1-131.el6_4 will be installed ---> Package perl-version.x86_64 3:0.77-131.el6_4 will be installed --> Running transaction check ---> Package perl-Pod-Escapes.x86_64 1:1.04-131.el6_4 will be installed --> Finished Dependency Resolution Dependencies Resolved =====================================================================================================================================================================================  Package                                      Arch                          Version                                   Repository                                                Size ===================================================================================================================================================================================== Installing:  MySQL-server                                 x86_64                        5.6.15-1.el6                              /MySQL-server-5.6.15-1.el6.x86_64                        235 M Installing for dependencies:  perl                                         x86_64                        4:5.10.1-131.el6_4                        updates                                                   10 M  perl-Module-Pluggable                        x86_64                        1:3.90-131.el6_4                          updates                                                   39 k  perl-Pod-Escapes                             x86_64                        1:1.04-131.el6_4                          updates                                                   31 k  perl-Pod-Simple                              x86_64                        1:3.13-131.el6_4                          updates                                                  211 k  perl-libs                                    x86_64                        4:5.10.1-131.el6_4                        updates                                                  577 k  perl-version                                 x86_64                        3:0.77-131.el6_4                          updates                                                   50 k Transaction Summary ===================================================================================================================================================================================== Install       7 Package(s) Total size: 246 M Total download size: 11 M Installed size: 270 M Is this ok [y/N]: y Downloading Packages: (1/6): perl-5.10.1-131.el6_4.x86_64.rpm                                                                                                                       |  10 MB     00:02 (2/6): perl-Module-Pluggable-3.90-131.el6_4.x86_64.rpm                                                                                                        |  39 kB     00:00 (3/6): perl-Pod-Escapes-1.04-131.el6_4.x86_64.rpm                                                                                                             |  31 kB     00:00 (4/6): perl-Pod-Simple-3.13-131.el6_4.x86_64.rpm                                                                                                              | 211 kB     00:00 (5/6): perl-libs-5.10.1-131.el6_4.x86_64.rpm                                                                                                                  | 577 kB     00:00 (6/6): perl-version-0.77-131.el6_4.x86_64.rpm                                                                                                                 |  50 kB     00:00 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Total                                                                                                                                                2.3 MB/s |  11 MB     00:04 Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction   Installing : 1:perl-Pod-Escapes-1.04-131.el6_4.x86_64                                                                                                                          1/7   Installing : 4:perl-libs-5.10.1-131.el6_4.x86_64                                                                                                                               2/7   Installing : 3:perl-version-0.77-131.el6_4.x86_64                                                                                                                              3/7   Installing : 1:perl-Module-Pluggable-3.90-131.el6_4.x86_64                                                                                                                     4/7   Installing : 1:perl-Pod-Simple-3.13-131.el6_4.x86_64                                                                                                                           5/7   Installing : 4:perl-5.10.1-131.el6_4.x86_64                                                                                                                                    6/7   Installing : MySQL-server-5.6.15-1.el6.x86_64                                                                                                                                  7/7 2013-09-04 19:29:17 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2013-09-04 19:29:18 2668 [Note] InnoDB: The InnoDB memory heap is disabled 2013-09-04 19:29:18 2668 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins 2013-09-04 19:29:18 2668 [Note] InnoDB: Compressed tables use zlib 1.2.3 2013-09-04 19:29:18 2668 [Note] InnoDB: Using Linux native AIO 2013-09-04 19:29:18 2668 [Note] InnoDB: Using CPU crc32 instructions 2013-09-04 19:29:18 2668 [Note] InnoDB: Initializing buffer pool, size = 128.0M 2013-09-04 19:29:19 2668 [Note] InnoDB: Completed initialization of buffer pool 2013-09-04 19:29:19 2668 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created! 2013-09-04 19:29:19 2668 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB 2013-09-04 19:29:19 2668 [Note] InnoDB: Database physically writes the file full: wait... 2013-09-04 19:29:20 2668 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB 2013-09-04 19:29:21 2668 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB 2013-09-04 19:29:22 2668 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0 2013-09-04 19:29:22 2668 [Warning] InnoDB: New log files created, LSN=45781 2013-09-04 19:29:22 2668 [Note] InnoDB: Doublewrite buffer not found: creating new 2013-09-04 19:29:22 2668 [Note] InnoDB: Doublewrite buffer created 2013-09-04 19:29:22 2668 [Note] InnoDB: 128 rollback segment(s) are active. 2013-09-04 19:29:22 2668 [Warning] InnoDB: Creating foreign key constraint system tables. 2013-09-04 19:29:22 2668 [Note] InnoDB: Foreign key constraint system tables created 2013-09-04 19:29:22 2668 [Note] InnoDB: Creating tablespace and datafile system tables. 2013-09-04 19:29:22 2668 [Note] InnoDB: Tablespace and datafile system tables created. 2013-09-04 19:29:22 2668 [Note] InnoDB: Waiting for purge to start 2013-09-04 19:29:22 2668 [Note] InnoDB: 5.6.15 started; log sequence number 0 2013-09-04 19:29:24 2668 [Note] Binlog end 2013-09-04 19:29:24 2668 [Note] InnoDB: FTS optimize thread exiting. 2013-09-04 19:29:24 2668 [Note] InnoDB: Starting shutdown... 2013-09-04 19:29:25 2668 [Note] InnoDB: Shutdown completed; log sequence number 1625977 A random root password has been set. You will find it in '/root/.mysql_secret'. 2013-09-04 19:29:25 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2013-09-04 19:29:25 2691 [Note] InnoDB: The InnoDB memory heap is disabled 2013-09-04 19:29:25 2691 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins 2013-09-04 19:29:25 2691 [Note] InnoDB: Compressed tables use zlib 1.2.3 2013-09-04 19:29:25 2691 [Note] InnoDB: Using Linux native AIO 2013-09-04 19:29:25 2691 [Note] InnoDB: Using CPU crc32 instructions 2013-09-04 19:29:25 2691 [Note] InnoDB: Initializing buffer pool, size = 128.0M 2013-09-04 19:29:25 2691 [Note] InnoDB: Completed initialization of buffer pool 2013-09-04 19:29:25 2691 [Note] InnoDB: Highest supported file format is Barracuda. 2013-09-04 19:29:25 2691 [Note] InnoDB: 128 rollback segment(s) are active. 2013-09-04 19:29:25 2691 [Note] InnoDB: Waiting for purge to start 2013-09-04 19:29:25 2691 [Note] InnoDB: 5.6.15 started; log sequence number 1625977 2013-09-04 19:29:26 2691 [Note] Binlog end 2013-09-04 19:29:26 2691 [Note] InnoDB: FTS optimize thread exiting. 2013-09-04 19:29:26 2691 [Note] InnoDB: Starting shutdown... 2013-09-04 19:29:27 2691 [Note] InnoDB: Shutdown completed; log sequence number 1625987 A RANDOM PASSWORD HAS BEEN SET FOR THE MySQL root USER ! You will find that password in '/root/.mysql_secret'. You must change that password on your first connect, no other statement but 'SET PASSWORD' will be accepted. See the manual for the semantics of the 'password expired' flag. Also, the account for the anonymous user has been removed. In addition, you can run:   /usr/bin/mysql_secure_installation which will also give you the option of removing the test database. This is strongly recommended for production servers. See the manual for more instructions. 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 New default config file was created as /usr/my.cnf and will be used by default by the server when you start it. You may edit this file to change server settings   Verifying  : 1:perl-Pod-Escapes-1.04-131.el6_4.x86_64                                                                                                                          1/7   Verifying  : 1:perl-Pod-Simple-3.13-131.el6_4.x86_64                                                                                                                           2/7   Verifying  : 4:perl-5.10.1-131.el6_4.x86_64                                                                                                                                    3/7   Verifying  : 4:perl-libs-5.10.1-131.el6_4.x86_64                                                                                                                               4/7   Verifying  : 3:perl-version-0.77-131.el6_4.x86_64                                                                                                                              5/7   Verifying  : MySQL-server-5.6.15-1.el6.x86_64                                                                                                                                  6/7   Verifying  : 1:perl-Module-Pluggable-3.90-131.el6_4.x86_64                                                                                                                     7/7 Installed:   MySQL-server.x86_64 0:5.6.15-1.el6 Dependency Installed:   perl.x86_64 4:5.10.1-131.el6_4          perl-Module-Pluggable.x86_64 1:3.90-131.el6_4     perl-Pod-Escapes.x86_64 1:1.04-131.el6_4     perl-Pod-Simple.x86_64 1:3.13-131.el6_4   perl-libs.x86_64 4:5.10.1-131.el6_4     perl-version.x86_64 3:0.77-131.el6_4 Complete!
  4. MySQL-clientをインストールする
    yum localinstall MySQL-client-5.6.15-1.rhel5.x86_64.rpm
  5. インストールされたことを確認する
    • 入力コマンド
      yum list installed | grep -i mys
    • 出力(rpmを使用して強制インストールした場合)
      [root@main1 ~]# yum list installed | grep -i mys MySQL-client.x86_64    5.6.15-1.el6     @/MySQL-client-5.6.15-1.el6.x86_64 MySQL-server.x86_64    5.6.15-1.el6     installed mysql-libs.x86_64      5.1.66-2.el6_3   @anaconda-CentOS-201303020151.x86_64/6.4
    • 出力(「Compatibility Libraries」をインストールした場合)
      [root@main2 ~]# yum list installed | grep -i mys MySQL-client.x86_64    5.6.15-1.el6     @/MySQL-client-5.6.15-1.el6.x86_64 MySQL-server.x86_64    5.6.15-1.el6     @/MySQL-server-5.6.15-1.el6.x86_64 MySQL-shared-compat.x86_64                        5.6.15-1.el6     @/MySQL-shared-compat-5.6.15-1.el6.x86_64
      なお、初期設定ファイルは/usr/my.cnfに作成される。
      内容は以下のとおりである。

      # The random password set for the root user at Wed Sep  4 19:29:23 2013 (local time): qJdaNNPL [root@main2 ~]# cat /usr/my.cnf # For advice on how to change settings please see # http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html [mysqld] # Remove leading # and set to the amount of RAM for the most important data # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%. # innodb_buffer_pool_size = 128M # Remove leading # to turn on a very important data integrity option: logging # changes to the binary log between backups. # log_bin # These are commonly set, remove the # and set as required. # basedir = ..... # datadir = ..... # port = ..... # server_id = ..... # socket = ..... # Remove leading # to set options mainly useful for reporting servers. # The server defaults are faster for transactions and fast SELECTs. # Adjust sizes as needed, experiment to find the optimal values. # join_buffer_size = 128M # sort_buffer_size = 2M # read_rnd_buffer_size = 2M sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES [root@main2 ~]# cat /usr/my.cnf # For advice on how to change settings please see # http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html [mysqld] # Remove leading # and set to the amount of RAM for the most important data # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%. # innodb_buffer_pool_size = 128M # Remove leading # to turn on a very important data integrity option: logging # changes to the binary log between backups. # log_bin # These are commonly set, remove the # and set as required. # basedir = ..... # datadir = ..... # port = ..... # server_id = ..... # socket = ..... # Remove leading # to set options mainly useful for reporting servers. # The server defaults are faster for transactions and fast SELECTs. # Adjust sizes as needed, experiment to find the optimal values. # join_buffer_size = 128M # sort_buffer_size = 2M # read_rnd_buffer_size = 2M sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES [root@main2 ~]# cat /usr/my.cnf # For advice on how to change settings please see # http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html [mysqld] # Remove leading # and set to the amount of RAM for the most important data # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%. # innodb_buffer_pool_size = 128M # Remove leading # to turn on a very important data integrity option: logging # changes to the binary log between backups. # log_bin # These are commonly set, remove the # and set as required. # basedir = ..... # datadir = ..... # port = ..... # server_id = ..... # socket = ..... # Remove leading # to set options mainly useful for reporting servers. # The server defaults are faster for transactions and fast SELECTs. # Adjust sizes as needed, experiment to find the optimal values. # join_buffer_size = 128M # sort_buffer_size = 2M # read_rnd_buffer_size = 2M sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

 

ソースパッケージからインストール




ソースコードからインストール


ソースコードからインストールすることで、インストール先を変更したり、
不要な機能を削除したりさまざまなオプションを指定できる。

  1. rootになる
    su -
  2. mysqlユーザを作成する
    useradd --user-group --no-create-home --shell /sbin/nologin mysql
  3. 関連パッケージをインストールする
    yum install gcc -y yum install gcc-c++ -y yum install cmake -y yum install perl -y yum install bison -y yum install ncurses-devel -y # 一括インストールの場合 yum install gcc gcc-c++ cmake perl bison ncurses-devel -y
  4. OSにデフォルトでインストールされているMySQLの設定ファイルを削除する
    rm -f /etc/my.cnf
  5. scpやwgetを使用してソースコードをダウンロードする
    wget http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.15.tar.gz
  6. 展開する
    tar xzfv mysql-*.tar.gz
  7. MySQLディレクトリへ移動する
    cd mysql-*
  8. コンパイル最適化設定を行う
    export CFLAGS="-O3 -m64 -march=native" export CXXFLAGS=$CFLAGS # make時にinclude/mysqld_error.hでIllegal instruction include/mysqld_error.hエラーが出る場合は-march=nativeオプションは外す
  9. MySQLのインストール場所とデータ用ディレクトリを分ける場合は、データ用ディレクトリを作成する
    # MySQLのデータ格納場所を/mysql-dataとする mkdir -p -m 774 /mysql-data chown mysql:mysql /mysql-data
  10. インストール設定を行う
    # MySQLのインストールパスを/usr/local/mysql-5.6.15とする cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql-5.6.15 -DMYSQL_DATADIR=/mysql-data 2>&1 | tee cmake.log # このコマンドの後、CMakeCache.txtファイルが生成されるので、全てのオプション値が確認できる
    Buildオプションは以下
    http://dev.mysql.com/doc/refman/5.6/en/source-configuration-options.html
    デフォルト値は以下(./configure –helpで表示)
    // Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel CMAKE_BUILD_TYPE:STRING= // install prefix CMAKE_INSTALL_PREFIX:PATH=/usr/local/mysql // Set to true if this is a community build COMMUNITY_BUILD:BOOL=ON // Enable profiling ENABLED_PROFILING:BOOL=ON // Enable debug sync (debug builds only) ENABLE_DEBUG_SYNC:BOOL=ON // Download and build 3rd party source code components, e.g. google mock ENABLE_DOWNLOADS:BOOL=OFF // Enable gcov (debug, Linux builds only) ENABLE_GCOV:BOOL=OFF // Enable gprof (optimized, Linux builds only) ENABLE_GPROF:BOOL=OFF // Enable SASL on InnoDB Memcached ENABLE_MEMCACHED_SASL:BOOL=OFF // Enable SASL on InnoDB Memcached ENABLE_MEMCACHED_SASL_PWDB:BOOL=OFF //  Selection of features. Options are  - xsmall :  - small: embedded  - classic: embedded + archive + federated + blackhole  - large :  embedded + archive + federated + blackhole + innodb  - xlarge:  embedded + archive + federated + blackhole + innodb + partition  - community:  all  features (currently == xlarge) FEATURE_SET:STRING=community // Installation directory layout. Options are: STANDALONE (as in zip or tar.gz installer), RPM, DEB, SVR4 INSTALL_LAYOUT:STRING=STANDALONE // default MySQL data directory MYSQL_DATADIR:PATH=/usr/local/mysql/data // MySQL maintainer-specific development environment MYSQL_MAINTAINER_MODE:BOOL=OFF // Support tracing of Optimizer OPTIMIZER_TRACE:BOOL=ON // Link ARCHIVE statically to the server WITH_ARCHIVE_STORAGE_ENGINE:BOOL=ON // Enable address sanitizer WITH_ASAN:BOOL=OFF // Link BLACKHOLE statically to the server WITH_BLACKHOLE_STORAGE_ENGINE:BOOL=ON // Use dbug/safemutex WITH_DEBUG:BOOL=OFF // Use flags from cmake/build_configurations/compiler_options.cmake WITH_DEFAULT_COMPILER_OPTIONS:BOOL=ON // Use feature set in cmake/build_configurations/feature_set.cmake WITH_DEFAULT_FEATURE_SET:BOOL=ON // By default use bundled editline WITH_EDITLINE:STRING=bundled // Compile MySQL with embedded server WITH_EMBEDDED_SERVER:BOOL=ON // WITH_EXAMPLE_STORAGE_ENGINE:BOOL=OFF // Options are: none, complex, all WITH_EXTRA_CHARSETS:STRING=all // Link FEDERATED statically to the server WITH_FEDERATED_STORAGE_ENGINE:BOOL=ON // Link INNOBASE statically to the server WITH_INNOBASE_STORAGE_ENGINE:BOOL=ON // WITH_INNODB_MEMCACHED:BOOL=OFF // By default use bundled libevent on this platform WITH_LIBEVENT:STRING=bundled // Compile with tcp wrappers support WITH_LIBWRAP:BOOL=OFF // Link PARTITION statically to the server WITH_PARTITION_STORAGE_ENGINE:BOOL=ON // Link PERFSCHEMA statically to the server WITH_PERFSCHEMA_STORAGE_ENGINE:BOOL=ON // Generate PIC objects WITH_PIC:BOOL=OFF // bundled (use yassl), yes (prefer os library if present, otherwise use bundled), system (use os library), </path/to/custom/installation> WITH_SSL:STRING=bundled // Compile MySQL with unit tests WITH_UNIT_TESTS:BOOL=ON // Valgrind instrumentation WITH_VALGRIND:BOOL=OFF // WITH_ZLIB:STRING=bundled
  11. インストールする
    make 2>&1 | tee make.log make install 2>&1 | tee make_install.log
  12. 起動スクリプトを設定
    cp support-files/mysql.server /etc/init.d/mysqld chmod 554 /etc/init.d/mysqld chkconfig --add mysqld # 登録を確認する chkconfig --list mysqld
  13. インストールに使用したパッケージを削除する
    cd ../ rm -rf mysql-*
  14. MySQLのシンボリックリンクを作成する
    ln -s /usr/local/mysql-5.6.15 /usr/local/mysql
    これによって、複数のバージョンのApacheを同居させ、リンクを切り替えることで、バージョン変更が可能
  15. 共通した環境とするために環境変数を設定する
    export MYSQL_HOME=/usr/local/mysql export MYSQL_DATA=/mysql-data
  16. ツール類にパスを通す
    export PATH=$MYSQL_HOME/bin:$PATH
  17. 環境変数を再起動後も有効にする
    vi /etc/bashrc # 以下を追記する export MYSQL_HOME=/usr/local/mysql export MYSQL_DATA=/mysql-data export PATH=$MYSQL_HOME/bin:$PATH
  18. 空の設定ファイルを作成する
    echo "[mysqld]" > $MYSQL_HOME/my.cnf

 

MySQL初期作業

 

初期データベースの作成


MySQLは管理情報自体も自身のデータベース内で管理するが、
インストール直後にはそのデータベースが作成されていないため、別途作成する。

cd $MYSQL_HOME scripts/mysql_install_db --datadir=$MYSQL_DATA --user=mysql

完了後、カレントディレクトリに設定ファイルが生成されるので、削除する。

rm -f my.cnf

所有者の変更を行う。

chown mysql:mysql $MYSQL_DATA chown mysql:mysql $MYSQL_DATA/* chown mysql:mysql $MYSQL_DATA/*/*

 

 

MySQLの起動


インストールが完了したら、MySQLが動作するかどうか確認のため、MySQLを起動する。
初期設定ファイルは存在しないはずなので、デフォルトで起動する。

mysqld_safe &

起動オプションはプロセスを出力することで確認できる。

ps aux | grep mysql | grep -v grep

次のように表示される。

mysql     7567  0.9 43.8 1007536 447544 pts/0  Sl   21:22   0:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/mysql-data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/mysql-data/mysql2.local.err --pid-file=/mysql-data/mysql2.local.pid

 

セキュア化


インストール直後のデフォルト状態では様々なセキュリティ上のリスクが存在する。
それらをまとめて修正できるのが、mysql_secure_installationスクリプトである。
MySQL Serverをインストールしたら、MySQL Serverを起動し、最初に実行するのが良い。

このスクリプトでは以下を行う。



rootユーザの初期パスワードが/root/.mysql_secretに記載されているので、コピーしておく。
上記がない場合、パスワードは空文字列。

以下スクリプトを実行する。対話的に実行されるが、パスワードの入力以外は Y を入力しておけばよい。

mysql_secure_installation

 

 

接続確認


rootユーザでログインできることを確認する。

mysql -p

 


削除されたtestデータベース以外に「information_schema」、「mysql」、「performance_schema」データベースが
初期状態で作成されているが、いずれも必要なのでおいておく。

MySQLの設定

 

設定方法

 

my.confについて


MySQLの設定はmy.confファイルに記述する。
ここにはMySQLサーバの設定のほかMySQLクライアントなどMySQLに関する全ての設定を記述する。
ただし、サーバの設定はmysqldセクションというようにセクションで区切られる。
MySQL起動オプションで明示的に上記設定ファイルのパスを指定することもできるが、
指定しなかった場合は、以下のファイルなどから設定が自動的に読み込まれる。

  1. /etc/my.cnf
  2. /etc/mysql/my.cnf
  3. SYSCONFDIR/my.cnf (SYSCONFDIRはMySQLビルド時に指定したパス。デフォルトではインストール先のディレクトリ)
  4. $MYSQL_HOME/my.cnf
  5. –dafaults-extra-file (MySQL起動オプションで設定ファイルのパスを指定する)
  6. ~/my.cnf
  7. コマンドラインオプション (MySQL起動オプションで設定値を指定する)


上記の順に設定が読み込まれ、重複した場合は後から設定された(読み込まれた)ものが有効になる。
なお、–dafaults-fileオプションを使用してファイルを指定した場合、そのファイル以外の設定ファイルは読み込まれなくなる。
設定ファイルによる設定を反映させる場合、MySQLの再起動が必要となる。

 

変数について


設定ファイルによる設定のほか、起動時にオプションとして渡したり、
mysqlコマンドによって動作中のMySQLに設定を行うことができる。
各設定値は変数として表され、変数の値を変更することで、設定を変更できる。
各変数の意味はこちらを参照。

 



なお、変数名のアンダースコア(_)はハイフン(-)に置換可能。

現在の変数の一覧はmysqladminコマンドで確認できる。

mysqladmin variables -p


変数の初期値は以下のとおりである。

+--------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Variable_name                                          | Value                                                                                                                                                                                                                                                                                                                                            | +--------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | auto_increment_increment                               | 1                                                                                                                                                                                                                                                                                                                                                | | auto_increment_offset                                  | 1                                                                                                                                                                                                                                                                                                                                                | | autocommit                                             | ON                                                                                                                                                                                                                                                                                                                                               | | automatic_sp_privileges                                | ON                                                                                                                                                                                                                                                                                                                                               | | back_log                                               | 80                                                                                                                                                                                                                                                                                                                                               | | basedir                                                | /usr/local/mysql                                                                                                                                                                                                                                                                                                                                 | | big_tables                                             | OFF                                                                                                                                                                                                                                                                                                                                              | | bind_address                                           | *                                                                                                                                                                                                                                                                                                                                                | | binlog_cache_size                                      | 32768                                                                                                                                                                                                                                                                                                                                            | | binlog_checksum                                        | CRC32                                                                                                                                                                                                                                                                                                                                            | | binlog_direct_non_transactional_updates                | OFF                                                                                                                                                                                                                                                                                                                                              | | binlog_format                                          | STATEMENT                                                                                                                                                                                                                                                                                                                                        | | binlog_max_flush_queue_time                            | 0                                                                                                                                                                                                                                                                                                                                                | | binlog_order_commits                                   | ON                                                                                                                                                                                                                                                                                                                                               | | binlog_row_image                                       | FULL                                                                                                                                                                                                                                                                                                                                             | | binlog_rows_query_log_events                           | OFF                                                                                                                                                                                                                                                                                                                                              | | binlog_stmt_cache_size                                 | 32768                                                                                                                                                                                                                                                                                                                                            | | bulk_insert_buffer_size                                | 8388608                                                                                                                                                                                                                                                                                                                                          | | character_set_client                                   | latin1                                                                                                                                                                                                                                                                                                                                           | | character_set_connection                               | latin1                                                                                                                                                                                                                                                                                                                                           | | character_set_database                                 | latin1                                                                                                                                                                                                                                                                                                                                           | | character_set_filesystem                               | binary                                                                                                                                                                                                                                                                                                                                           | | character_set_results                                  | latin1                                                                                                                                                                                                                                                                                                                                           | | character_set_server                                   | latin1                                                                                                                                                                                                                                                                                                                                           | | character_set_system                                   | utf8                                                                                                                                                                                                                                                                                                                                             | | character_sets_dir                                     | /usr/local/mysql-5.6.15/share/charsets/                                                                                                                                                                                                                                                                                                          | | collation_connection                                   | latin1_swedish_ci                                                                                                                                                                                                                                                                                                                                | | collation_database                                     | latin1_swedish_ci                                                                                                                                                                                                                                                                                                                                | | collation_server                                       | latin1_swedish_ci                                                                                                                                                                                                                                                                                                                                | | completion_type                                        | NO_CHAIN                                                                                                                                                                                                                                                                                                                                         | | concurrent_insert                                      | AUTO                                                                                                                                                                                                                                                                                                                                             | | connect_timeout                                        | 10                                                                                                                                                                                                                                                                                                                                               | | core_file                                              | OFF                                                                                                                                                                                                                                                                                                                                              | | datadir                                                | /mysql-data/                                                                                                                                                                                                                                                                                                                                     | | date_format                                            | %Y-%m-%d                                                                                                                                                                                                                                                                                                                                         | | datetime_format                                        | %Y-%m-%d %H:%i:%s                                                                                                                                                                                                                                                                                                                                | | default_storage_engine                                 | InnoDB                                                                                                                                                                                                                                                                                                                                           | | default_tmp_storage_engine                             | InnoDB                                                                                                                                                                                                                                                                                                                                           | | default_week_format                                    | 0                                                                                                                                                                                                                                                                                                                                                | | delay_key_write                                        | ON                                                                                                                                                                                                                                                                                                                                               | | delayed_insert_limit                                   | 100                                                                                                                                                                                                                                                                                                                                              | | delayed_insert_timeout                                 | 300                                                                                                                                                                                                                                                                                                                                              | | delayed_queue_size                                     | 1000                                                                                                                                                                                                                                                                                                                                             | | disconnect_on_expired_password                         | ON                                                                                                                                                                                                                                                                                                                                               | | div_precision_increment                                | 4                                                                                                                                                                                                                                                                                                                                                | | end_markers_in_json                                    | OFF                                                                                                                                                                                                                                                                                                                                              | | enforce_gtid_consistency                               | OFF                                                                                                                                                                                                                                                                                                                                              | | eq_range_index_dive_limit                              | 10                                                                                                                                                                                                                                                                                                                                               | | event_scheduler                                        | OFF                                                                                                                                                                                                                                                                                                                                              | | expire_logs_days                                       | 0                                                                                                                                                                                                                                                                                                                                                | | explicit_defaults_for_timestamp                        | OFF                                                                                                                                                                                                                                                                                                                                              | | flush                                                  | OFF                                                                                                                                                                                                                                                                                                                                              | | flush_time                                             | 0                                                                                                                                                                                                                                                                                                                                                | | foreign_key_checks                                     | ON                                                                                                                                                                                                                                                                                                                                               | | ft_boolean_syntax                                      | + -><()~*:""&|                                                                                                                                                                                                                                                                                                                                   | | ft_max_word_len                                        | 84                                                                                                                                                                                                                                                                                                                                               | | ft_min_word_len                                        | 4                                                                                                                                                                                                                                                                                                                                                | | ft_query_expansion_limit                               | 20                                                                                                                                                                                                                                                                                                                                               | | ft_stopword_file                                       | (built-in)                                                                                                                                                                                                                                                                                                                                       | | general_log                                            | OFF                                                                                                                                                                                                                                                                                                                                              | | general_log_file                                       | /mysql-data/mysql2.log                                                                                                                                                                                                                                                                                                                           | | group_concat_max_len                                   | 1024                                                                                                                                                                                                                                                                                                                                             | | gtid_executed                                          |                                                                                                                                                                                                                                                                                                                                                  | | gtid_mode                                              | OFF                                                                                                                                                                                                                                                                                                                                              | | gtid_owned                                             |                                                                                                                                                                                                                                                                                                                                                  | | gtid_purged                                            |                                                                                                                                                                                                                                                                                                                                                  | | have_compress                                          | YES                                                                                                                                                                                                                                                                                                                                              | | have_crypt                                             | YES                                                                                                                                                                                                                                                                                                                                              | | have_dynamic_loading                                   | YES                                                                                                                                                                                                                                                                                                                                              | | have_geometry                                          | YES                                                                                                                                                                                                                                                                                                                                              | | have_openssl                                           | DISABLED                                                                                                                                                                                                                                                                                                                                         | | have_profiling                                         | YES                                                                                                                                                                                                                                                                                                                                              | | have_query_cache                                       | YES                                                                                                                                                                                                                                                                                                                                              | | have_rtree_keys                                        | YES                                                                                                                                                                                                                                                                                                                                              | | have_ssl                                               | DISABLED                                                                                                                                                                                                                                                                                                                                         | | have_symlink                                           | YES                                                                                                                                                                                                                                                                                                                                              | | host_cache_size                                        | 279                                                                                                                                                                                                                                                                                                                                              | | hostname                                               | mysql2.local                                                                                                                                                                                                                                                                                                                                     | | ignore_builtin_innodb                                  | OFF                                                                                                                                                                                                                                                                                                                                              | | ignore_db_dirs                                         |                                                                                                                                                                                                                                                                                                                                                  | | init_connect                                           |                                                                                                                                                                                                                                                                                                                                                  | | init_file                                              |                                                                                                                                                                                                                                                                                                                                                  | | init_slave                                             |                                                                                                                                                                                                                                                                                                                                                  | | innodb_adaptive_flushing                               | ON                                                                                                                                                                                                                                                                                                                                               | | innodb_adaptive_flushing_lwm                           | 10                                                                                                                                                                                                                                                                                                                                               | | innodb_adaptive_hash_index                             | ON                                                                                                                                                                                                                                                                                                                                               | | innodb_adaptive_max_sleep_delay                        | 150000                                                                                                                                                                                                                                                                                                                                           | | innodb_additional_mem_pool_size                        | 8388608                                                                                                                                                                                                                                                                                                                                          | | innodb_api_bk_commit_interval                          | 5                                                                                                                                                                                                                                                                                                                                                | | innodb_api_disable_rowlock                             | OFF                                                                                                                                                                                                                                                                                                                                              | | innodb_api_enable_binlog                               | OFF                                                                                                                                                                                                                                                                                                                                              | | innodb_api_enable_mdl                                  | OFF                                                                                                                                                                                                                                                                                                                                              | | innodb_api_trx_level                                   | 0                                                                                                                                                                                                                                                                                                                                                | | innodb_autoextend_increment                            | 64                                                                                                                                                                                                                                                                                                                                               | | innodb_autoinc_lock_mode                               | 1                                                                                                                                                                                                                                                                                                                                                | | innodb_buffer_pool_dump_at_shutdown                    | OFF                                                                                                                                                                                                                                                                                                                                              | | innodb_buffer_pool_dump_now                            | OFF                                                                                                                                                                                                                                                                                                                                              | | innodb_buffer_pool_filename                            | ib_buffer_pool                                                                                                                                                                                                                                                                                                                                   | | innodb_buffer_pool_instances                           | 8                                                                                                                                                                                                                                                                                                                                                | | innodb_buffer_pool_load_abort                          | OFF                                                                                                                                                                                                                                                                                                                                              | | innodb_buffer_pool_load_at_startup                     | OFF                                                                                                                                                                                                                                                                                                                                              | | innodb_buffer_pool_load_now                            | OFF                                                                                                                                                                                                                                                                                                                                              | | innodb_buffer_pool_size                                | 134217728                                                                                                                                                                                                                                                                                                                                        | | innodb_change_buffer_max_size                          | 25                                                                                                                                                                                                                                                                                                                                               | | innodb_change_buffering                                | all                                                                                                                                                                                                                                                                                                                                              | | innodb_checksum_algorithm                              | innodb                                                                                                                                                                                                                                                                                                                                           | | innodb_checksums                                       | ON                                                                                                                                                                                                                                                                                                                                               | | innodb_cmp_per_index_enabled                           | OFF                                                                                                                                                                                                                                                                                                                                              | | innodb_commit_concurrency                              | 0                                                                                                                                                                                                                                                                                                                                                | | innodb_compression_failure_threshold_pct               | 5                                                                                                                                                                                                                                                                                                                                                | | innodb_compression_level                               | 6                                                                                                                                                                                                                                                                                                                                                | | innodb_compression_pad_pct_max                         | 50                                                                                                                                                                                                                                                                                                                                               | | innodb_concurrency_tickets                             | 5000                                                                                                                                                                                                                                                                                                                                             | | innodb_data_file_path                                  | ibdata1:12M:autoextend                                                                                                                                                                                                                                                                                                                           | | innodb_data_home_dir                                   |                                                                                                                                                                                                                                                                                                                                                  | | innodb_disable_sort_file_cache                         | OFF                                                                                                                                                                                                                                                                                                                                              | | innodb_doublewrite                                     | ON                                                                                                                                                                                                                                                                                                                                               | | innodb_fast_shutdown                                   | 1                                                                                                                                                                                                                                                                                                                                                | | innodb_file_format                                     | Antelope                                                                                                                                                                                                                                                                                                                                         | | innodb_file_format_check                               | ON                                                                                                                                                                                                                                                                                                                                               | | innodb_file_format_max                                 | Antelope                                                                                                                                                                                                                                                                                                                                         | | innodb_file_per_table                                  | ON                                                                                                                                                                                                                                                                                                                                               | | innodb_flush_log_at_timeout                            | 1                                                                                                                                                                                                                                                                                                                                                | | innodb_flush_log_at_trx_commit                         | 1                                                                                                                                                                                                                                                                                                                                                | | innodb_flush_method                                    |                                                                                                                                                                                                                                                                                                                                                  | | innodb_flush_neighbors                                 | 1                                                                                                                                                                                                                                                                                                                                                | | innodb_flushing_avg_loops                              | 30                                                                                                                                                                                                                                                                                                                                               | | innodb_force_load_corrupted                            | OFF                                                                                                                                                                                                                                                                                                                                              | | innodb_force_recovery                                  | 0                                                                                                                                                                                                                                                                                                                                                | | innodb_ft_aux_table                                    |                                                                                                                                                                                                                                                                                                                                                  | | innodb_ft_cache_size                                   | 8000000                                                                                                                                                                                                                                                                                                                                          | | innodb_ft_enable_diag_print                            | OFF                                                                                                                                                                                                                                                                                                                                              | | innodb_ft_enable_stopword                              | ON                                                                                                                                                                                                                                                                                                                                               | | innodb_ft_max_token_size                               | 84                                                                                                                                                                                                                                                                                                                                               | | innodb_ft_min_token_size                               | 3                                                                                                                                                                                                                                                                                                                                                | | innodb_ft_num_word_optimize                            | 2000                                                                                                                                                                                                                                                                                                                                             | | innodb_ft_result_cache_limit                           | 2000000000                                                                                                                                                                                                                                                                                                                                       | | innodb_ft_server_stopword_table                        |                                                                                                                                                                                                                                                                                                                                                  | | innodb_ft_sort_pll_degree                              | 2                                                                                                                                                                                                                                                                                                                                                | | innodb_ft_total_cache_size                             | 640000000                                                                                                                                                                                                                                                                                                                                        | | innodb_ft_user_stopword_table                          |                                                                                                                                                                                                                                                                                                                                                  | | innodb_io_capacity                                     | 200                                                                                                                                                                                                                                                                                                                                              | | innodb_io_capacity_max                                 | 2000                                                                                                                                                                                                                                                                                                                                             | | innodb_large_prefix                                    | OFF                                                                                                                                                                                                                                                                                                                                              | | innodb_lock_wait_timeout                               | 50                                                                                                                                                                                                                                                                                                                                               | | innodb_locks_unsafe_for_binlog                         | OFF                                                                                                                                                                                                                                                                                                                                              | | innodb_log_buffer_size                                 | 8388608                                                                                                                                                                                                                                                                                                                                          | | innodb_log_compressed_pages                            | ON                                                                                                                                                                                                                                                                                                                                               | | innodb_log_file_size                                   | 50331648                                                                                                                                                                                                                                                                                                                                         | | innodb_log_files_in_group                              | 2                                                                                                                                                                                                                                                                                                                                                | | innodb_log_group_home_dir                              | ./                                                                                                                                                                                                                                                                                                                                               | | innodb_lru_scan_depth                                  | 1024                                                                                                                                                                                                                                                                                                                                             | | innodb_max_dirty_pages_pct                             | 75                                                                                                                                                                                                                                                                                                                                               | | innodb_max_dirty_pages_pct_lwm                         | 0                                                                                                                                                                                                                                                                                                                                                | | innodb_max_purge_lag                                   | 0                                                                                                                                                                                                                                                                                                                                                | | innodb_max_purge_lag_delay                             | 0                                                                                                                                                                                                                                                                                                                                                | | innodb_mirrored_log_groups                             | 1                                                                                                                                                                                                                                                                                                                                                | | innodb_monitor_disable                                 |                                                                                                                                                                                                                                                                                                                                                  | | innodb_monitor_enable                                  |                                                                                                                                                                                                                                                                                                                                                  | | innodb_monitor_reset                                   |                                                                                                                                                                                                                                                                                                                                                  | | innodb_monitor_reset_all                               |                                                                                                                                                                                                                                                                                                                                                  | | innodb_old_blocks_pct                                  | 37                                                                                                                                                                                                                                                                                                                                               | | innodb_old_blocks_time                                 | 1000                                                                                                                                                                                                                                                                                                                                             | | innodb_online_alter_log_max_size                       | 134217728                                                                                                                                                                                                                                                                                                                                        | | innodb_open_files                                      | 2000                                                                                                                                                                                                                                                                                                                                             | | innodb_optimize_fulltext_only                          | OFF                                                                                                                                                                                                                                                                                                                                              | | innodb_page_size                                       | 16384                                                                                                                                                                                                                                                                                                                                            | | innodb_print_all_deadlocks                             | OFF                                                                                                                                                                                                                                                                                                                                              | | innodb_purge_batch_size                                | 300                                                                                                                                                                                                                                                                                                                                              | | innodb_purge_threads                                   | 1                                                                                                                                                                                                                                                                                                                                                | | innodb_random_read_ahead                               | OFF                                                                                                                                                                                                                                                                                                                                              | | innodb_read_ahead_threshold                            | 56                                                                                                                                                                                                                                                                                                                                               | | innodb_read_io_threads                                 | 4                                                                                                                                                                                                                                                                                                                                                | | innodb_read_only                                       | OFF                                                                                                                                                                                                                                                                                                                                              | | innodb_replication_delay                               | 0                                                                                                                                                                                                                                                                                                                                                | | innodb_rollback_on_timeout                             | OFF                                                                                                                                                                                                                                                                                                                                              | | innodb_rollback_segments                               | 128                                                                                                                                                                                                                                                                                                                                              | | innodb_sort_buffer_size                                | 1048576                                                                                                                                                                                                                                                                                                                                          | | innodb_spin_wait_delay                                 | 6                                                                                                                                                                                                                                                                                                                                                | | innodb_stats_auto_recalc                               | ON                                                                                                                                                                                                                                                                                                                                               | | innodb_stats_method                                    | nulls_equal                                                                                                                                                                                                                                                                                                                                      | | innodb_stats_on_metadata                               | OFF                                                                                                                                                                                                                                                                                                                                              | | innodb_stats_persistent                                | ON                                                                                                                                                                                                                                                                                                                                               | | innodb_stats_persistent_sample_pages                   | 20                                                                                                                                                                                                                                                                                                                                               | | innodb_stats_sample_pages                              | 8                                                                                                                                                                                                                                                                                                                                                | | innodb_stats_transient_sample_pages                    | 8                                                                                                                                                                                                                                                                                                                                                | | innodb_strict_mode                                     | OFF                                                                                                                                                                                                                                                                                                                                              | | innodb_support_xa                                      | ON                                                                                                                                                                                                                                                                                                                                               | | innodb_sync_array_size                                 | 1                                                                                                                                                                                                                                                                                                                                                | | innodb_sync_spin_loops                                 | 30                                                                                                                                                                                                                                                                                                                                               | | innodb_table_locks                                     | ON                                                                                                                                                                                                                                                                                                                                               | | innodb_thread_concurrency                              | 0                                                                                                                                                                                                                                                                                                                                                | | innodb_thread_sleep_delay                              | 10000                                                                                                                                                                                                                                                                                                                                            | | innodb_undo_directory                                  | .                                                                                                                                                                                                                                                                                                                                                | | innodb_undo_logs                                       | 128                                                                                                                                                                                                                                                                                                                                              | | innodb_undo_tablespaces                                | 0                                                                                                                                                                                                                                                                                                                                                | | innodb_use_native_aio                                  | OFF                                                                                                                                                                                                                                                                                                                                              | | innodb_use_sys_malloc                                  | ON                                                                                                                                                                                                                                                                                                                                               | | innodb_version                                         | 5.6.15                                                                                                                                                                                                                                                                                                                                           | | innodb_write_io_threads                                | 4                                                                                                                                                                                                                                                                                                                                                | | interactive_timeout                                    | 28800                                                                                                                                                                                                                                                                                                                                            | | join_buffer_size                                       | 262144                                                                                                                                                                                                                                                                                                                                           | | keep_files_on_create                                   | OFF                                                                                                                                                                                                                                                                                                                                              | | key_buffer_size                                        | 8388608                                                                                                                                                                                                                                                                                                                                          | | key_cache_age_threshold                                | 300                                                                                                                                                                                                                                                                                                                                              | | key_cache_block_size                                   | 1024                                                                                                                                                                                                                                                                                                                                             | | key_cache_division_limit                               | 100                                                                                                                                                                                                                                                                                                                                              | | large_files_support                                    | ON                                                                                                                                                                                                                                                                                                                                               | | large_page_size                                        | 0                                                                                                                                                                                                                                                                                                                                                | | large_pages                                            | OFF                                                                                                                                                                                                                                                                                                                                              | | lc_messages                                            | en_US                                                                                                                                                                                                                                                                                                                                            | | lc_messages_dir                                        | /usr/local/mysql-5.6.15/share/                                                                                                                                                                                                                                                                                                                   | | lc_time_names                                          | en_US                                                                                                                                                                                                                                                                                                                                            | | license                                                | GPL                                                                                                                                                                                                                                                                                                                                              | | local_infile                                           | ON                                                                                                                                                                                                                                                                                                                                               | | lock_wait_timeout                                      | 31536000                                                                                                                                                                                                                                                                                                                                         | | locked_in_memory                                       | OFF                                                                                                                                                                                                                                                                                                                                              | | log_bin                                                | OFF                                                                                                                                                                                                                                                                                                                                              | | log_bin_basename                                       |                                                                                                                                                                                                                                                                                                                                                  | | log_bin_index                                          |                                                                                                                                                                                                                                                                                                                                                  | | log_bin_trust_function_creators                        | OFF                                                                                                                                                                                                                                                                                                                                              | | log_bin_use_v1_row_events                              | OFF                                                                                                                                                                                                                                                                                                                                              | | log_error                                              | /mysql-data/mysql2.local.err                                                                                                                                                                                                                                                                                                                     | | log_output                                             | FILE                                                                                                                                                                                                                                                                                                                                             | | log_queries_not_using_indexes                          | OFF                                                                                                                                                                                                                                                                                                                                              | | log_slave_updates                                      | OFF                                                                                                                                                                                                                                                                                                                                              | | log_slow_admin_statements                              | OFF                                                                                                                                                                                                                                                                                                                                              | | log_slow_slave_statements                              | OFF                                                                                                                                                                                                                                                                                                                                              | | log_throttle_queries_not_using_indexes                 | 0                                                                                                                                                                                                                                                                                                                                                | | log_warnings                                           | 1                                                                                                                                                                                                                                                                                                                                                | | long_query_time                                        | 10.000000                                                                                                                                                                                                                                                                                                                                        | | low_priority_updates                                   | OFF                                                                                                                                                                                                                                                                                                                                              | | lower_case_file_system                                 | OFF                                                                                                                                                                                                                                                                                                                                              | | lower_case_table_names                                 | 0                                                                                                                                                                                                                                                                                                                                                | | master_info_repository                                 | FILE                                                                                                                                                                                                                                                                                                                                             | | master_verify_checksum                                 | OFF                                                                                                                                                                                                                                                                                                                                              | | max_allowed_packet                                     | 4194304                                                                                                                                                                                                                                                                                                                                          | | max_binlog_cache_size                                  | 18446744073709547520                                                                                                                                                                                                                                                                                                                             | | max_binlog_size                                        | 1073741824                                                                                                                                                                                                                                                                                                                                       | | max_binlog_stmt_cache_size                             | 18446744073709547520                                                                                                                                                                                                                                                                                                                             | | max_connect_errors                                     | 100                                                                                                                                                                                                                                                                                                                                              | | max_connections                                        | 151                                                                                                                                                                                                                                                                                                                                              | | max_delayed_threads                                    | 20                                                                                                                                                                                                                                                                                                                                               | | max_error_count                                        | 64                                                                                                                                                                                                                                                                                                                                               | | max_heap_table_size                                    | 16777216                                                                                                                                                                                                                                                                                                                                         | | max_insert_delayed_threads                             | 20                                                                                                                                                                                                                                                                                                                                               | | max_join_size                                          | 18446744073709551615                                                                                                                                                                                                                                                                                                                             | | max_length_for_sort_data                               | 1024                                                                                                                                                                                                                                                                                                                                             | | max_prepared_stmt_count                                | 16382                                                                                                                                                                                                                                                                                                                                            | | max_relay_log_size                                     | 0                                                                                                                                                                                                                                                                                                                                                | | max_seeks_for_key                                      | 18446744073709551615                                                                                                                                                                                                                                                                                                                             | | max_sort_length                                        | 1024                                                                                                                                                                                                                                                                                                                                             | | max_sp_recursion_depth                                 | 0                                                                                                                                                                                                                                                                                                                                                | | max_tmp_tables                                         | 32                                                                                                                                                                                                                                                                                                                                               | | max_user_connections                                   | 0                                                                                                                                                                                                                                                                                                                                                | | max_write_lock_count                                   | 18446744073709551615                                                                                                                                                                                                                                                                                                                             | | metadata_locks_cache_size                              | 1024                                                                                                                                                                                                                                                                                                                                             | | metadata_locks_hash_instances                          | 8                                                                                                                                                                                                                                                                                                                                                | | min_examined_row_limit                                 | 0                                                                                                                                                                                                                                                                                                                                                | | multi_range_count                                      | 256                                                                                                                                                                                                                                                                                                                                              | | myisam_data_pointer_size                               | 6                                                                                                                                                                                                                                                                                                                                                | | myisam_max_sort_file_size                              | 9223372036853727232                                                                                                                                                                                                                                                                                                                              | | myisam_mmap_size                                       | 18446744073709551615                                                                                                                                                                                                                                                                                                                             | | myisam_recover_options                                 | OFF                                                                                                                                                                                                                                                                                                                                              | | myisam_repair_threads                                  | 1                                                                                                                                                                                                                                                                                                                                                | | myisam_sort_buffer_size                                | 8388608                                                                                                                                                                                                                                                                                                                                          | | myisam_stats_method                                    | nulls_unequal                                                                                                                                                                                                                                                                                                                                    | | myisam_use_mmap                                        | OFF                                                                                                                                                                                                                                                                                                                                              | | net_buffer_length                                      | 16384                                                                                                                                                                                                                                                                                                                                            | | net_read_timeout                                       | 30                                                                                                                                                                                                                                                                                                                                               | | net_retry_count                                        | 10                                                                                                                                                                                                                                                                                                                                               | | net_write_timeout                                      | 60                                                                                                                                                                                                                                                                                                                                               | | new                                                    | OFF                                                                                                                                                                                                                                                                                                                                              | | old                                                    | OFF                                                                                                                                                                                                                                                                                                                                              | | old_alter_table                                        | OFF                                                                                                                                                                                                                                                                                                                                              | | old_passwords                                          | 0                                                                                                                                                                                                                                                                                                                                                | | open_files_limit                                       | 5000                                                                                                                                                                                                                                                                                                                                             | | optimizer_prune_level                                  | 1                                                                                                                                                                                                                                                                                                                                                | | optimizer_search_depth                                 | 62                                                                                                                                                                                                                                                                                                                                               | | optimizer_switch                                       | index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,engine_condition_pushdown=on,index_condition_pushdown=on,mrr=on,mrr_cost_based=on,block_nested_loop=on,batched_key_access=off,materialization=on,semijoin=on,loosescan=on,firstmatch=on,subquery_materialization_cost_based=on,use_index_extensions=on | | optimizer_trace                                        | enabled=off,one_line=off                                                                                                                                                                                                                                                                                                                         | | optimizer_trace_features                               | greedy_search=on,range_optimizer=on,dynamic_range=on,repeated_subselect=on                                                                                                                                                                                                                                                                       | | optimizer_trace_limit                                  | 1                                                                                                                                                                                                                                                                                                                                                | | optimizer_trace_max_mem_size                           | 16384                                                                                                                                                                                                                                                                                                                                            | | optimizer_trace_offset                                 | -1                                                                                                                                                                                                                                                                                                                                               | | performance_schema                                     | ON                                                                                                                                                                                                                                                                                                                                               | | performance_schema_accounts_size                       | 100                                                                                                                                                                                                                                                                                                                                              | | performance_schema_digests_size                        | 10000                                                                                                                                                                                                                                                                                                                                            | | performance_schema_events_stages_history_long_size     | 10000                                                                                                                                                                                                                                                                                                                                            | | performance_schema_events_stages_history_size          | 10                                                                                                                                                                                                                                                                                                                                               | | performance_schema_events_statements_history_long_size | 10000                                                                                                                                                                                                                                                                                                                                            | | performance_schema_events_statements_history_size      | 10                                                                                                                                                                                                                                                                                                                                               | | performance_schema_events_waits_history_long_size      | 10000                                                                                                                                                                                                                                                                                                                                            | | performance_schema_events_waits_history_size           | 10                                                                                                                                                                                                                                                                                                                                               | | performance_schema_hosts_size                          | 100                                                                                                                                                                                                                                                                                                                                              | | performance_schema_max_cond_classes                    | 80                                                                                                                                                                                                                                                                                                                                               | | performance_schema_max_cond_instances                  | 3504                                                                                                                                                                                                                                                                                                                                             | | performance_schema_max_file_classes                    | 50                                                                                                                                                                                                                                                                                                                                               | | performance_schema_max_file_handles                    | 32768                                                                                                                                                                                                                                                                                                                                            | | performance_schema_max_file_instances                  | 7693                                                                                                                                                                                                                                                                                                                                             | | performance_schema_max_mutex_classes                   | 200                                                                                                                                                                                                                                                                                                                                              | | performance_schema_max_mutex_instances                 | 15906                                                                                                                                                                                                                                                                                                                                            | | performance_schema_max_rwlock_classes                  | 40                                                                                                                                                                                                                                                                                                                                               | | performance_schema_max_rwlock_instances                | 9102                                                                                                                                                                                                                                                                                                                                             | | performance_schema_max_socket_classes                  | 10                                                                                                                                                                                                                                                                                                                                               | | performance_schema_max_socket_instances                | 322                                                                                                                                                                                                                                                                                                                                              | | performance_schema_max_stage_classes                   | 150                                                                                                                                                                                                                                                                                                                                              | | performance_schema_max_statement_classes               | 168                                                                                                                                                                                                                                                                                                                                              | | performance_schema_max_table_handles                   | 4000                                                                                                                                                                                                                                                                                                                                             | | performance_schema_max_table_instances                 | 12500                                                                                                                                                                                                                                                                                                                                            | | performance_schema_max_thread_classes                  | 50                                                                                                                                                                                                                                                                                                                                               | | performance_schema_max_thread_instances                | 402                                                                                                                                                                                                                                                                                                                                              | | performance_schema_session_connect_attrs_size          | 512                                                                                                                                                                                                                                                                                                                                              | | performance_schema_setup_actors_size                   | 100                                                                                                                                                                                                                                                                                                                                              | | performance_schema_setup_objects_size                  | 100                                                                                                                                                                                                                                                                                                                                              | | performance_schema_users_size                          | 100                                                                                                                                                                                                                                                                                                                                              | | pid_file                                               | /mysql-data/mysql2.local.pid                                                                                                                                                                                                                                                                                                                     | | plugin_dir                                             | /usr/local/mysql/lib/plugin/                                                                                                                                                                                                                                                                                                                     | | port                                                   | 3306                                                                                                                                                                                                                                                                                                                                             | | preload_buffer_size                                    | 32768                                                                                                                                                                                                                                                                                                                                            | | profiling                                              | OFF                                                                                                                                                                                                                                                                                                                                              | | profiling_history_size                                 | 15                                                                                                                                                                                                                                                                                                                                               | | protocol_version                                       | 10                                                                                                                                                                                                                                                                                                                                               | | query_alloc_block_size                                 | 8192                                                                                                                                                                                                                                                                                                                                             | | query_cache_limit                                      | 1048576                                                                                                                                                                                                                                                                                                                                          | | query_cache_min_res_unit                               | 4096                                                                                                                                                                                                                                                                                                                                             | | query_cache_size                                       | 1048576                                                                                                                                                                                                                                                                                                                                          | | query_cache_type                                       | OFF                                                                                                                                                                                                                                                                                                                                              | | query_cache_wlock_invalidate                           | OFF                                                                                                                                                                                                                                                                                                                                              | | query_prealloc_size                                    | 8192                                                                                                                                                                                                                                                                                                                                             | | range_alloc_block_size                                 | 4096                                                                                                                                                                                                                                                                                                                                             | | read_buffer_size                                       | 131072                                                                                                                                                                                                                                                                                                                                           | | read_only                                              | OFF                                                                                                                                                                                                                                                                                                                                              | | read_rnd_buffer_size                                   | 262144                                                                                                                                                                                                                                                                                                                                           | | relay_log                                              |                                                                                                                                                                                                                                                                                                                                                  | | relay_log_basename                                     |                                                                                                                                                                                                                                                                                                                                                  | | relay_log_index                                        |                                                                                                                                                                                                                                                                                                                                                  | | relay_log_info_file                                    | relay-log.info                                                                                                                                                                                                                                                                                                                                   | | relay_log_info_repository                              | FILE                                                                                                                                                                                                                                                                                                                                             | | relay_log_purge                                        | ON                                                                                                                                                                                                                                                                                                                                               | | relay_log_recovery                                     | OFF                                                                                                                                                                                                                                                                                                                                              | | relay_log_space_limit                                  | 0                                                                                                                                                                                                                                                                                                                                                | | report_host                                            |                                                                                                                                                                                                                                                                                                                                                  | | report_password                                        |                                                                                                                                                                                                                                                                                                                                                  | | report_port                                            | 3306                                                                                                                                                                                                                                                                                                                                             | | report_user                                            |                                                                                                                                                                                                                                                                                                                                                  | | rpl_stop_slave_timeout                                 | 31536000                                                                                                                                                                                                                                                                                                                                         | | secure_auth                                            | ON                                                                                                                                                                                                                                                                                                                                               | | secure_file_priv                                       |                                                                                                                                                                                                                                                                                                                                                  | | server_id                                              | 0                                                                                                                                                                                                                                                                                                                                                | | server_id_bits                                         | 32                                                                                                                                                                                                                                                                                                                                               | | server_uuid                                            | f25c1f2b-8295-11e3-9663-000c29033885                                                                                                                                                                                                                                                                                                             | | skip_external_locking                                  | ON                                                                                                                                                                                                                                                                                                                                               | | skip_name_resolve                                      | OFF                                                                                                                                                                                                                                                                                                                                              | | skip_networking                                        | OFF                                                                                                                                                                                                                                                                                                                                              | | skip_show_database                                     | OFF                                                                                                                                                                                                                                                                                                                                              | | slave_allow_batching                                   | OFF                                                                                                                                                                                                                                                                                                                                              | | slave_checkpoint_group                                 | 512                                                                                                                                                                                                                                                                                                                                              | | slave_checkpoint_period                                | 300                                                                                                                                                                                                                                                                                                                                              | | slave_compressed_protocol                              | OFF                                                                                                                                                                                                                                                                                                                                              | | slave_exec_mode                                        | STRICT                                                                                                                                                                                                                                                                                                                                           | | slave_load_tmpdir                                      | /tmp                                                                                                                                                                                                                                                                                                                                             | | slave_max_allowed_packet                               | 1073741824                                                                                                                                                                                                                                                                                                                                       | | slave_net_timeout                                      | 3600                                                                                                                                                                                                                                                                                                                                             | | slave_parallel_workers                                 | 0                                                                                                                                                                                                                                                                                                                                                | | slave_pending_jobs_size_max                            | 16777216                                                                                                                                                                                                                                                                                                                                         | | slave_rows_search_algorithms                           | TABLE_SCAN,INDEX_SCAN                                                                                                                                                                                                                                                                                                                            | | slave_skip_errors                                      | OFF                                                                                                                                                                                                                                                                                                                                              | | slave_sql_verify_checksum                              | ON                                                                                                                                                                                                                                                                                                                                               | | slave_transaction_retries                              | 10                                                                                                                                                                                                                                                                                                                                               | | slave_type_conversions                                 |                                                                                                                                                                                                                                                                                                                                                  | | slow_launch_time                                       | 2                                                                                                                                                                                                                                                                                                                                                | | slow_query_log                                         | OFF                                                                                                                                                                                                                                                                                                                                              | | slow_query_log_file                                    | /mysql-data/mysql2-slow.log                                                                                                                                                                                                                                                                                                                      | | socket                                                 | /tmp/mysql.sock                                                                                                                                                                                                                                                                                                                                  | | sort_buffer_size                                       | 262144                                                                                                                                                                                                                                                                                                                                           | | sql_auto_is_null                                       | OFF                                                                                                                                                                                                                                                                                                                                              | | sql_big_selects                                        | ON                                                                                                                                                                                                                                                                                                                                               | | sql_buffer_result                                      | OFF                                                                                                                                                                                                                                                                                                                                              | | sql_log_bin                                            | ON                                                                                                                                                                                                                                                                                                                                               | | sql_log_off                                            | OFF                                                                                                                                                                                                                                                                                                                                              | | sql_mode                                               | STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION                                                                                                                                                                                                                                                                                                       | | sql_notes                                              | ON                                                                                                                                                                                                                                                                                                                                               | | sql_quote_show_create                                  | ON                                                                                                                                                                                                                                                                                                                                               | | sql_safe_updates                                       | OFF                                                                                                                                                                                                                                                                                                                                              | | sql_select_limit                                       | 18446744073709551615                                                                                                                                                                                                                                                                                                                             | | sql_slave_skip_counter                                 | 0                                                                                                                                                                                                                                                                                                                                                | | sql_warnings                                           | OFF                                                                                                                                                                                                                                                                                                                                              | | ssl_ca                                                 |                                                                                                                                                                                                                                                                                                                                                  | | ssl_capath                                             |                                                                                                                                                                                                                                                                                                                                                  | | ssl_cert                                               |                                                                                                                                                                                                                                                                                                                                                  | | ssl_cipher                                             |                                                                                                                                                                                                                                                                                                                                                  | | ssl_crl                                                |                                                                                                                                                                                                                                                                                                                                                  | | ssl_crlpath                                            |                                                                                                                                                                                                                                                                                                                                                  | | ssl_key                                                |                                                                                                                                                                                                                                                                                                                                                  | | storage_engine                                         | InnoDB                                                                                                                                                                                                                                                                                                                                           | | stored_program_cache                                   | 256                                                                                                                                                                                                                                                                                                                                              | | sync_binlog                                            | 0                                                                                                                                                                                                                                                                                                                                                | | sync_frm                                               | ON                                                                                                                                                                                                                                                                                                                                               | | sync_master_info                                       | 10000                                                                                                                                                                                                                                                                                                                                            | | sync_relay_log                                         | 10000                                                                                                                                                                                                                                                                                                                                            | | sync_relay_log_info                                    | 10000                                                                                                                                                                                                                                                                                                                                            | | system_time_zone                                       | JST                                                                                                                                                                                                                                                                                                                                              | | table_definition_cache                                 | 1400                                                                                                                                                                                                                                                                                                                                             | | table_open_cache                                       | 2000                                                                                                                                                                                                                                                                                                                                             | | table_open_cache_instances                             | 1                                                                                                                                                                                                                                                                                                                                                | | thread_cache_size                                      | 9                                                                                                                                                                                                                                                                                                                                                | | thread_concurrency                                     | 10                                                                                                                                                                                                                                                                                                                                               | | thread_handling                                        | one-thread-per-connection                                                                                                                                                                                                                                                                                                                        | | thread_stack                                           | 262144                                                                                                                                                                                                                                                                                                                                           | | time_format                                            | %H:%i:%s                                                                                                                                                                                                                                                                                                                                         | | time_zone                                              | SYSTEM                                                                                                                                                                                                                                                                                                                                           | | timed_mutexes                                          | OFF                                                                                                                                                                                                                                                                                                                                              | | tmp_table_size                                         | 16777216                                                                                                                                                                                                                                                                                                                                         | | tmpdir                                                 | /tmp                                                                                                                                                                                                                                                                                                                                             | | transaction_alloc_block_size                           | 8192                                                                                                                                                                                                                                                                                                                                             | | transaction_prealloc_size                              | 4096                                                                                                                                                                                                                                                                                                                                             | | tx_isolation                                           | REPEATABLE-READ                                                                                                                                                                                                                                                                                                                                  | | tx_read_only                                           | OFF                                                                                                                                                                                                                                                                                                                                              | | unique_checks                                          | ON                                                                                                                                                                                                                                                                                                                                               | | updatable_views_with_limit                             | YES                                                                                                                                                                                                                                                                                                                                              | | version                                                | 5.6.15                                                                                                                                                                                                                                                                                                                                           | | version_comment                                        | Source distribution                                                                                                                                                                                                                                                                                                                              | | version_compile_machine                                | x86_64                                                                                                                                                                                                                                                                                                                                           | | version_compile_os                                     | Linux                                                                                                                                                                                                                                                                                                                                            | | wait_timeout                                           | 28800                                                                                                                                                                                                                                                                                                                                            | +--------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+



設定ファイルの作成


my.cnfが存在しないはずなので、新しく作成する。

touch $MYSQL_HOME/my.cnf chown mysql:mysql $MYSQL_HOME/my.cnf chmod 664 $MYSQL_HOME/my.cnf

 

基本設定

 

MySQL情報

 

version=5.6.15 version_comment=Source distribution version_compile_machine=x86_64 version_compile_os=Linux license=GPL protocol_version=10



パス


MySQLで使用する各種パスを指定する。
パスは絶対パスで指定し、basedirからの相対パスで指定することはできない。















時間



 






ファイル





 



 




サーバー



 

 

文字コード
















MySQLがデフォルトで使用する文字コードはlatin1であり、日本語は扱えない。
そのため、日本語を扱う場合は設定が必要となる。





文字コードが異なる間でデータのやり取りが行われる場合、MySQLで自動で変換が行われる。
ただし、変換の負荷を考えると文字コードはクライアント環境も含めて統一したほうがよい。
全体で使用する文字コードを設定してもテーブル毎に個別に文字コードを設定することは可能で、
マルチバイト文字を使用しない場合は”latin1″を使用したほうがデータ量は少なくできる。
ただし、やはり変換負荷が発生するので、ストレージ容量より処理速度を優先して文字コードは統一したほうがよい。
マルチバイト文字を一切使用しないのであれば、デフォルトのままで、
使用する、もしくは今後使用する可能性があるのであれば、character_set_serverをutf8にするのがよい。
接続元がWindows環境であれば、”cp932″(Windowsのshift-jis)、
UTF-8で表現できない特殊な文字を使用する場合は”utf8mb4″(4byteのUTF8)を設定する。
なお、character_set_serverを変更すると自動でcharacter_set_databaseなど関連する変数も変更される。
また、初期状態で作成されるinformation_schema、mysql、performance_schemaのデータベースの文字コードはutf8となっている。

 

エラーメッセージ







エラーメッセージは通常英語で出力されるが、日本語を含むほかの言語で出力することができる。

 

 

 

 

 







ネットワーク



hostname=mysql2.local max_connect_errors=100 skip_networking=OFF



 

 

 

max_user_connections=0



アドレス・ポート


MySQLサーバデーモンが使用するアドレス・ポート番号。
これらは起動時にのみ指定可能で、起動後の変数の変更は不可。

 

bind_address=<IPアドレス>

 

 



 

port=<ポート番号>

 

 

port=3306

 




クライアント間通信


クライアント間通信の際に使用されるパラメータを設定する。
ネットワークの品質が悪い場合は調整が必要。

 

 

 

 

 

 

 

 

 









タイムアウト

connect_timeout

接続開始時に接続が完了するまでのタイムアウト時間。



wait_timeout

対話式ではないコネクションで、通信がないコネクションを強制的に閉じるまでのタイムアウト時間(秒)

 

interactive_timeout

対話式のコネクションで、通信がないコネクションを強制的に閉じるまでのタイムアウト時間(秒)



最大接続数

MySQL Serverへの最大接続数。
1接続につき1つのファイルのオープン(ファイルディスクリプタ)が必要になるので、
多数の接続を行う場合は、open_files_limit値も合わせて変更する必要がある。

 



 

max_connections=300





最大接続待ち数


TCP接続処理を開始し、実際にMySQLへ接続を完了するまでの接続待ち(リッスン)キューのサイズ。

 



 

back_log=80



SSL









クエリー・コマンド




STRICTモード


日付関連


処理



演算子とデータ型



SQL分


互換性







セット





出力例(OFF)

set end_markers_in_json=off; explain format=json select * from mysql.user; +--------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | EXPLAIN                                                                                                                                                            | +--------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | {   "query_block": {     "select_id": 1,     "table": {       "table_name": "user",       "access_type": "ALL",       "rows": 3,       "filtered": 100     }   } } | +--------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 1 row in set, 1 warning (0.00 sec)











バッファ


レコードの読み出しやSQLを実行する際に各種バッファ

query_alloc_block_size=8192
query_prealloc_size=8192





 

 











トランザクション



transaction_alloc_block_size=8192
transaction_prealloc_size=4096
tx_isolation=REPEATABLE-READ
tx_read_only=OFF




クエリーオプティマイザー



optimizer_prune_level=1
optimizer_search_depth=62
optimizer_switch=index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,engine_condition_pushdown=on,index_condition_pushdown=on,mrr=on,mrr_cost_based=on,block_nested_loop=on,batched_key_access=off,materialization=on,semijoin=on,loosescan=on,firstmatch=on,subquery_materialization_cost_based=on,use_index_extensions=on
optimizer_trace=enabled=off,one_line=off
optimizer_trace_features=greedy_search=on,range_optimizer=on,dynamic_range=on,repeated_subselect=on
optimizer_trace_limit=1
optimizer_trace_max_mem_size=16384
optimizer_trace_offset=-1



キャッシュ

 

テーブルキャッシュ


テーブルキャッシュとは、MySQLがデータを保存するファイルを開いたときに作成する
ファイルへのポインタを格納するキャッシュのことである。
テーブルキャッシュはテーブルキャッシュインスタンスによって管理される。
テーブルキャッシュインスタンスはテーブルキャッシュ数÷テーブルキャッシュインスタンス数で
算出される数のキャッシュを扱う。
なお、table_open_cacheの値は最低でもmax_connectionsと同数にする必要がある。
これは同一のテーブルに対しても各スレッドはそれぞれでファイルを開くためである。









クエリキャッシュ


クエリキャッシュは発行されたSELECTクエリの結果をキャッシュする機能である。
キャッシュされるクエリは空白等も含めて完全に一致する場合のみ利用される。
キャッシュはクエリで利用されるテーブルに変更があった場合に破棄されるので、
必ずしも影響のある行に変更があったとは限らないが、変更検知のオーバーヘッドが少ないため、この方法が採用されている。









スレッド










ストレージエンジン



default_storage_engine=InnoDB
storage_engine=InnoDB



MEMORYストレージエンジン









MyISAMストレージエンジン



myisam_data_pointer_size=6
myisam_max_sort_file_size=9223372036853727232
myisam_mmap_size=18446744073709551615
myisam_recover_options=OFF
myisam_repair_threads=1
myisam_sort_buffer_size=8388608
myisam_stats_method=nulls_unequal
myisam_use_mmap=OFF
key_cache_age_threshold=300
key_cache_block_size=1024
key_cache_division_limit=100
key_buffer_size=8388608

ステータスのKey_read_requests/Key_reads、Key_write_requests/Key_writesでチューニング

concurrent_insert=AUTO
delay_key_write=ON
have_rtree_keys=YES
keep_files_on_create=OFF
read_rnd_buffer_size=262144
skip_external_locking=ON
key_buffer_size=8388608


 




 

 

 




InnoDB

 

バッファ


















ログ


Redoログ(クラッシュリカバリ用)の各種設定を行う










ダーティページ


ダーティページのディスクへの書き込み方式は旧来では以下のようなものであった。
・バッファ中のダーティページの割合を毎秒計測し、一定以上にならないようにディスクに書き込む
・redo logは決まった容量で、最後まで書き込むと先頭に戻って再度上書きしていくがredo logの残量がなくなり、上書きを行うタイミングで全てディスクへ書き込む
後者が発生すると、ディスクへ一度に全て書き込むため瞬間的に書き込み負荷が高まってしまう(sharp checkpoint)。
新方式では上記に加え、redo logの残量を計測して徐々にディスクに書き込む(adaptive flushing)。
新方式によって負荷の高まりに影響なくディスク書き込みの量が平準化されるので、スループットが上昇する。





 










スレッド














圧縮


InnoDBはテーブルデータやインデックスをディスク上のみでなく、メモリ上でも圧縮して保持する。
これは透過的に行われ、ユーザーは特に意識せずに圧縮を使用できる。
圧縮はページ単位で行われ、データ追加や変更に伴う圧縮後のデータサイズ増加に対応するために各ページは予備の領域(パディング)を持つ。
パディングは不足した場合に一定量まで増量できるが、その全領域を使い果たしたときページは分割され、2つのページになる。
この事象はINFORMATION_SCHEMA.INNODB_CMPテーブルのCOMPRESS_OPSの値がCOMPRESS_OPS_OKを超えているかで確認できる。
参考:http://dev.mysql.com/doc/refman/5.6/en/innodb-compression.html














memcachedインタフェース







テーブルフォーマット










ファイル










チェックサム












autocommit=(OFF | ON)
autocommit=ON

各SQL実行毎に自動でCOMMITするかどうか。
OFFにした場合は明示的にトランザクションの開始と終了を実行する必要がある。











・1:コミット時は毎回ログに書き出す。

・2:コミット時は毎回ログに書き出す。
ただし、Flush(ファイルシステムからディスクへの物理的な書き込み)は1秒間に1回行う。
つまり、ディスクがクラッシュした場合は最大1秒間のデータが喪失する。
MySQLプロセスがクラッシュした場合は問題ない。











使用すべきではない。
Controls whether innodb mutexes are timed out.






innodb_adaptive_hash_index=ON
innodb_additional_mem_pool_size=8388608
innodb_api_bk_commit_interval=5
innodb_api_disable_rowlock=OFF
innodb_api_enable_binlog=OFF
innodb_api_enable_mdl=OFF
innodb_api_trx_level=0
innodb_autoextend_increment=64
innodb_autoinc_lock_mode=1


innodb_disable_sort_file_cache=OFF
innodb_doublewrite=ON
innodb_fast_shutdown=1


innodb_flush_log_at_timeout=1
innodb_flush_log_at_trx_commit=1
innodb_flush_method=
innodb_flush_neighbors=1
innodb_flushing_avg_loops=30
innodb_force_load_corrupted=OFF
innodb_force_recovery=0
innodb_ft_aux_table=
innodb_ft_cache_size=8000000
innodb_ft_enable_diag_print=OFF
innodb_ft_enable_stopword=ON
innodb_ft_max_token_size=84
innodb_ft_min_token_size=3
innodb_ft_num_word_optimize=2000
innodb_ft_result_cache_limit=2000000000
innodb_ft_server_stopword_table=
innodb_ft_sort_pll_degree=2
innodb_ft_total_cache_size=640000000
innodb_ft_user_stopword_table=
innodb_io_capacity=200
innodb_io_capacity_max=2000
innodb_large_prefix=OFF
innodb_lock_wait_timeout=50
innodb_locks_unsafe_for_binlog=OFF


innodb_lru_scan_depth=1024
innodb_max_purge_lag=0
innodb_max_purge_lag_delay=0
innodb_mirrored_log_groups=1
innodb_monitor_disable=
innodb_monitor_enable=
innodb_monitor_reset=
innodb_monitor_reset_all=
innodb_old_blocks_pct=37
innodb_old_blocks_time=1000
innodb_online_alter_log_max_size=134217728


innodb_optimize_fulltext_only=OFF
innodb_page_size=16384
innodb_print_all_deadlocks=OFF
innodb_purge_batch_size=300
innodb_purge_threads=1
innodb_random_read_ahead=OFF
innodb_read_ahead_threshold=56
innodb_read_io_threads=4
innodb_read_only=OFF
innodb_replication_delay=0
innodb_rollback_on_timeout=OFF
innodb_rollback_segments=128
innodb_sort_buffer_size=1048576
innodb_spin_wait_delay=6
innodb_stats_auto_recalc=ON
innodb_stats_method=nulls_equal
innodb_stats_on_metadata=OFF
innodb_stats_persistent=ON
innodb_stats_persistent_sample_pages=20
innodb_stats_sample_pages=8
innodb_stats_transient_sample_pages=8
innodb_strict_mode=OFF
innodb_support_xa=ON
innodb_sync_array_size=1
innodb_sync_spin_loops=30
innodb_table_locks=ON
innodb_thread_sleep_delay=10000
innodb_undo_directory=.
innodb_undo_logs=128
innodb_undo_tablespaces=0
innodb_use_native_aio=OFF
innodb_use_sys_malloc=ON
innodb_version=5.6.15
innodb_write_io_threads=4
ignore_builtin_innodb=OFF
stored_program_cache=256
foreign_key_checks=ON
timed_mutexes=OFF

使用すべきではない。Controls whether innodb mutexes are timed out.

unique_checks=ON













ログ


SQL発行状況など各種ログを保存するための設定。
デフォルトでは大抵のログは保存されないので、ログが必要な場合は設定が必要である。

一般ログ


全てのSQLを記録する。
全てログを保存するとI/O負荷が高まるため、一時的にしか使用しない方がよい。



 



エラーログ


エラーログにはMySQLの起動・終了、エラーメッセージなどが出力される。





スロークエリログ


実行に一定以上の時間がかかったクエリを記録する。









バイナリログ


バイナリログは更新系クエリのログである。
バックアップからのロールフォワードに使用される。

 




 






デバッグログ









冗長



max_relay_log_size=0
relay_log=
relay_log_basename=
relay_log_index=
relay_log_info_file=relay-log.info
relay_log_info_repository=FILE
relay_log_purge=ON
relay_log_recovery=OFF
relay_log_space_limit=0
sync_binlog=0

バイナリログのディスク同期設定。
1の場合、ログの確実性。0の場合、パフォーマンスが向上。
サーバマシンの安定性を考慮して決定

sync_frm=ON
sync_master_info=10000
sync_relay_log=10000
sync_relay_log_info=10000
init_slave=
rpl_stop_slave_timeout=31536000
slave_allow_batching=OFF
slave_checkpoint_group=512
slave_checkpoint_period=300
slave_compressed_protocol=OFF
slave_exec_mode=STRICT
slave_load_tmpdir=/tmp
slave_max_allowed_packet=1073741824
slave_net_timeout=3600
slave_parallel_workers=0
slave_pending_jobs_size_max=16777216
slave_rows_search_algorithms=TABLE_SCAN,INDEX_SCAN
slave_skip_errors=OFF
slave_sql_verify_checksum=ON
slave_transaction_retries=10
slave_type_conversions=
sql_slave_skip_counter=0
report_host=
report_password=
report_port=3306
report_user=
gtid_executed=
gtid_mode=OFF
gtid_owned=
gtid_purged=
master_info_repository=FILE
master_verify_checksum=OFF
multi_range_count=256
log_slave_updates=OFF
log_slow_slave_statements=OFF





enforce_gtid_consistency=OFF

この変数は起動時に設定する必要があり、起動後は読み取り専用の変数。
設定する場合は、 –enforce-gtid-consistency オプションをつける。
ON状態にあるとき、トランザクションを保てないクエリーは使用不可となる。
具体的には以下である。
CREATE TABLE … SELECT statements
CREATE TEMPORARY TABLE statements inside transactions
Transactions or statements that update both transactional and nontransactional tables.



準同期レプリケーション





have_dynamic_loading=YES

準同期レプリケーションに必要なdynamic loadingをサポートしているかどうか。
この変数は変更不可能。



その他

 

内部一時テーブル





内部一時テーブルファイルの設定を行う。
内部一時テーブルのストレージエンジンはMyISAMである。
内部一時テーブルはユーザが作成するTEMPORARYとは別のもので、
UNIONによる結合などMySQLの内部で利用される。
内部一時テーブルは通常メモリ上に作成されるが、領域が不足すると
tmpdirで指定した場所に一時ファイルが作成される。
参考:How MySQL Uses Internal Temporary Tables

 

 






tmp_table_size=16777216
big_tables=OFF




TEMPORARYテーブル


CREATE TEMPORARY TABLEによって作成されるTEMPORARYテーブルの設定。
TEMPORARYテーブルはMEMORYストレージエンジンのデータベースとは異なる。

 



 

default_tmp_storage_engine=InnoDB



ホスト名解決



host_cache_size=279




GRANTで作成したユーザのアクセス元制限で、ホスト名を指定することができる。
指定した場合、アクセス毎にアクセス元のIPの逆引きでホスト名を取得し、比較を行う。
更にそのホスト名を正引きし、取得したIPとアクセス元IPの比較を行う。
大量にMySQLにアクセスする場合、この処理に非常に負荷がかかる。
これを避けるため、以下の設定を追加してDNSによる確認を止めることが可能である。

skip-name-resolve

ただし、localhostを含めてドメイン名を指定したユーザ制限ができないくなるので、
代わりにIPアドレスを直接指定する必要がある。(localhostの場合は127.0.0.1)

なお、/etc/hostsファイルに静的に名前情報を記述することでも
DNS処理を解決できるが、漏れが合った場合はDNS処理が行われてします。

いずれの方法でもIPアドレスの変更があった場合は、
設定の修正が必要となってしまう。



 



パフォーマンススキーマ



performance_schema=ON
performance_schema_accounts_size=100
performance_schema_digests_size=10000
performance_schema_events_stages_history_long_size=10000
performance_schema_events_stages_history_size=10
performance_schema_events_statements_history_long_size 10000
performance_schema_events_statements_history_size=10
performance_schema_events_waits_history_long_size=10000
performance_schema_events_waits_history_size=10
performance_schema_hosts_size=100
performance_schema_max_cond_classes=80
performance_schema_max_cond_instances=3504
performance_schema_max_file_classes=50
performance_schema_max_file_handles=32768
performance_schema_max_file_instances=7693
performance_schema_max_mutex_classes=200
performance_schema_max_mutex_instances=15906
performance_schema_max_rwlock_classes=40
performance_schema_max_rwlock_instances=9102
performance_schema_max_socket_classes=10
performance_schema_max_socket_instances=322
performance_schema_max_stage_classes=150
performance_schema_max_statement_classes=168
performance_schema_max_table_handles=4000
performance_schema_max_table_instances=12500
performance_schema_max_thread_classes=50
performance_schema_max_thread_instances=402
performance_schema_session_connect_attrs_size=512
performance_schema_setup_actors_size=100
performance_schema_setup_objects_size=100
performance_schema_users_size=100


全文検索



ft_boolean_syntax=+ -><()~*:””&|
ft_max_word_len=84
ft_min_word_len=4
ft_query_expansion_limit=20
ft_stopword_file=(built-in)


コアファイル(ダンプファイル)


エラー終了時にコアファイルを生成するかどうか。
コアファイルを取得する場合、MySQLでの設定のほか、次のカーネルパラメータを設定する必要がある。









automatic_sp_privileges=ON

stored routineの作成者に自動的にEXECUTEとALTER ROUTINEを実行する権限を与えるかどうか。


disconnect_on_expired_password=ON

期限切れパスワードをどう扱うか。



have_compress=YES

zlibによる圧縮・展開をサポートしているかどうか。
この変数は変更不可能。

have_crypt=YES

暗号化(crypt())をサポートしているかどうか。
この変数は変更不可能。

have_geometry=YES

Geometry機能をサポートしているかどうか。
この変数は変更不可能。

init_connect=

クライアントが接続されるたびにサーバで実行されるコマンド・クエリーを指定する

init_file=

サーバ起動時に実行するコマンド・クエリーが記述されたファイルのパスを指定する

large_files_support=ON

ラージファイル(2GB以上のサイズのファイル)をサポートしているかどうか。
この変数は変更不可能。

large_page_size=0

InnoDBでラージページ(4KB以上のページ)として扱えるページのサイズが設定される。
0の場合はサポートしていない。
この変数は変更不可能。

large_pages=OFF

InnoDBでラージページ(4KB以上のページ)をサポートしているかどうか。
この変数は変更不可能。

locked_in_memory=OFF
lower_case_file_system=OFF
lower_case_table_names=0

テーブルやデータベースがファイルシステム上でファイルやディレクトリとして保存される際、
ファイル名やディレクトリ名を小文字に変換するか指定する。

 



profiling=OFF
profiling_history_size=15


read_only=OFF
secure_auth=ON
secure_file_priv=



お薦めのデフォルトmy.cnf

[mysqld]
#BASIC CONFIGURATIONS
port=3306
character_set_server=utf8
skip-character-set-client-handshake
datadir=
skip-name-resolve
query_cache_type=ON
query_cache_wlock_invalidate=OFF

#PERFORMANCE CONFIGRATIONS
query_cache_size=1048576
query_cache_min_res_unit=4096
query_cache_limit=1048576


max_connections=300
table_open_cache
table_definition_cache
key_buffer_size
myisam_max_sort_file_size
myisam_recover
read_buffer_size
read_rnd_buffer_size
join_buffer_size

max_binlog_size
expire_logs_days
server_id
slow_query_log
long_query_time
log_queries_not_using_indexes
open_files_limit
skip_innodb
table_open_cache
table_definition_cache
innodb_buffer_pool_size
innodb_additional_mem_pool_size
innodb_data_file_path
innodb_data_home_dir
innodb_file_per_table
innodb_autoextend_increment
innodb_log_group_home_dir
innodb_log_files_in_group
innodb_log_file_size
innodb_log_buffer_size
innodb_flush_log_at_trx_commit
innodb_flush_method
innodb_thread_concurrency
innodb_commit_concurrency
innodb_concurrency_ticlets
innodb_sync_spin_loops
innodb_thread_sleep_delay
innodb_max_dirty_pages_pct





クライアント設定

クライアント設定を設定ファイルに記述する場合は[client]セクションか[mysql]セクションに記述する。
[client]セクションはmysqlを使用するクライアントソフト共通の設定を記載し、
[mysql]セクションにはmysqlコマンドでのみ使用する設定を記載する。

ログイン情報

 



ページャ

ページャを使用する場合、使用するページャを指定する

pager=(less|more)



警告の表示

クエリを実行した際に警告が発生すると、自動的にshow warningコマンドを実行する

show-warnings



文字コード

接続に使用する文字コードを指定する。
ターミナルの文字コードと合わせる必要がある。

default-character-set=<文字コード>



全件更新・削除の禁止

キーを指定しないupdate、deleteクエリの実行を禁止する。
これによってレコード全件を更新・削除してしまうことがなくなる。

safe-updates



プロンプトの変更

デフォルトのプロンプト mysql> を変更する

prompt=<プロンプト文>

 



クイックインストール

OSインストール直後からMySQLの初期設定までを行う方法を以下に記載する。
以下をコピーペーストすれば良い。


クエリー

クエリーの最後を;でなく\Gとすることで、表形式ではなく、
項目とその値の対応として表示させることができる。

一覧表示

データベース一覧

show databases;

パラメータ確認

ステータス確認

サーバステータス

show [session] status;



show global status;

 

+-----------------------------------------------+-------------+
| Variable_name | Value |
+-----------------------------------------------+-------------+
| Aborted_clients | 384 |
| Aborted_connects | 20029 |
| Binlog_cache_disk_use | 0 |
| Binlog_cache_use | 0 |
| Binlog_stmt_cache_disk_use | 0 |
| Binlog_stmt_cache_use | 0 |
| Bytes_received | 340 |
| Bytes_sent | 15698 |
| Com_admin_commands | 0 |
| Com_assign_to_keycache | 0 |
| Com_alter_db | 0 |
| Com_alter_db_upgrade | 0 |
| Com_alter_event | 0 |
| Com_alter_function | 0 |
| Com_alter_procedure | 0 |
| Com_alter_server | 0 |
| Com_alter_table | 0 |
| Com_alter_tablespace | 0 |
| Com_alter_user | 0 |
| Com_analyze | 0 |
| Com_begin | 0 |
| Com_binlog | 0 |
| Com_call_procedure | 0 |
| Com_change_db | 0 |
| Com_change_master | 0 |
| Com_check | 0 |
| Com_checksum | 0 |
| Com_commit | 0 |
| Com_create_db | 0 |
| Com_create_event | 0 |
| Com_create_function | 0 |
| Com_create_index | 0 |
| Com_create_procedure | 0 |
| Com_create_server | 0 |
| Com_create_table | 0 |
| Com_create_trigger | 0 |
| Com_create_udf | 0 |
| Com_create_user | 0 |
| Com_create_view | 0 |
| Com_dealloc_sql | 0 |
| Com_delete | 0 |
| Com_delete_multi | 0 |
| Com_do | 0 |
| Com_drop_db | 0 |
| Com_drop_event | 0 |
| Com_drop_function | 0 |
| Com_drop_index | 0 |
| Com_drop_procedure | 0 |
| Com_drop_server | 0 |
| Com_drop_table | 0 |
| Com_drop_trigger | 0 |
| Com_drop_user | 0 |
| Com_drop_view | 0 |
| Com_empty_query | 0 |
| Com_execute_sql | 0 |
| Com_flush | 0 |
| Com_get_diagnostics | 0 |
| Com_grant | 0 |
| Com_ha_close | 0 |
| Com_ha_open | 0 |
| Com_ha_read | 0 |
| Com_help | 0 |
| Com_insert | 0 |
| Com_insert_select | 0 |
| Com_install_plugin | 0 |
| Com_kill | 0 |
| Com_load | 0 |
| Com_lock_tables | 0 |
| Com_optimize | 0 |
| Com_preload_keys | 0 |
| Com_prepare_sql | 0 |
| Com_purge | 0 |
| Com_purge_before_date | 0 |
| Com_release_savepoint | 0 |
| Com_rename_table | 0 |
| Com_rename_user | 0 |
| Com_repair | 0 |
| Com_replace | 0 |
| Com_replace_select | 0 |
| Com_reset | 0 |
| Com_resignal | 0 |
| Com_revoke | 0 |
| Com_revoke_all | 0 |
| Com_rollback | 0 |
| Com_rollback_to_savepoint | 0 |
| Com_savepoint | 0 |
| Com_select | 1 |
| Com_set_option | 0 |
| Com_signal | 0 |
| Com_show_binlog_events | 0 |
| Com_show_binlogs | 0 |
| Com_show_charsets | 0 |
| Com_show_collations | 0 |
| Com_show_create_db | 0 |
| Com_show_create_event | 0 |
| Com_show_create_func | 0 |
| Com_show_create_proc | 0 |
| Com_show_create_table | 0 |
| Com_show_create_trigger | 0 |
| Com_show_databases | 0 |
| Com_show_engine_logs | 0 |
| Com_show_engine_mutex | 0 |
| Com_show_engine_status | 4 |
| Com_show_events | 0 |
| Com_show_errors | 0 |
| Com_show_fields | 0 |
| Com_show_function_code | 0 |
| Com_show_function_status | 0 |
| Com_show_grants | 0 |
| Com_show_keys | 0 |
| Com_show_master_status | 0 |
| Com_show_open_tables | 0 |
| Com_show_plugins | 0 |
| Com_show_privileges | 0 |
| Com_show_procedure_code | 0 |
| Com_show_procedure_status | 0 |
| Com_show_processlist | 0 |
| Com_show_profile | 0 |
| Com_show_profiles | 0 |
| Com_show_relaylog_events | 0 |
| Com_show_slave_hosts | 0 |
| Com_show_slave_status | 0 |
| Com_show_status | 1 |
| Com_show_storage_engines | 0 |
| Com_show_table_status | 0 |
| Com_show_tables | 0 |
| Com_show_triggers | 0 |
| Com_show_variables | 0 |
| Com_show_warnings | 0 |
| Com_slave_start | 0 |
| Com_slave_stop | 0 |
| Com_stmt_close | 0 |
| Com_stmt_execute | 0 |
| Com_stmt_fetch | 0 |
| Com_stmt_prepare | 0 |
| Com_stmt_reprepare | 0 |
| Com_stmt_reset | 0 |
| Com_stmt_send_long_data | 0 |
| Com_truncate | 0 |
| Com_uninstall_plugin | 0 |
| Com_unlock_tables | 0 |
| Com_update | 0 |
| Com_update_multi | 0 |
| Com_xa_commit | 0 |
| Com_xa_end | 0 |
| Com_xa_prepare | 0 |
| Com_xa_recover | 0 |
| Com_xa_rollback | 0 |
| Com_xa_start | 0 |
| Compression | OFF |
| Connection_errors_accept | 0 |
| Connection_errors_internal | 0 |
| Connection_errors_max_connections | 16886 |
| Connection_errors_peer_address | 0 |
| Connection_errors_select | 0 |
| Connection_errors_tcpwrap | 0 |
| Connections | 51525 |
| Created_tmp_disk_tables | 0 |
| Created_tmp_files | 790 |
| Created_tmp_tables | 0 |
| Delayed_errors | 0 |
| Delayed_insert_threads | 0 |
| Delayed_writes | 0 |
| Flush_commands | 1 |
| Handler_commit | 0 |
| Handler_delete | 0 |
| Handler_discover | 0 |
| Handler_external_lock | 0 |
| Handler_mrr_init | 0 |
| Handler_prepare | 0 |
| Handler_read_first | 0 |
| Handler_read_key | 0 |
| Handler_read_last | 0 |
| Handler_read_next | 0 |
| Handler_read_prev | 0 |
| Handler_read_rnd | 0 |
| Handler_read_rnd_next | 0 |
| Handler_rollback | 0 |
| Handler_savepoint | 0 |
| Handler_savepoint_rollback | 0 |
| Handler_update | 0 |
| Handler_write | 0 |
| Innodb_buffer_pool_dump_status | not started |
| Innodb_buffer_pool_load_status | not started |
| Innodb_buffer_pool_pages_data | 7166 |
| Innodb_buffer_pool_bytes_data | 117407744 |
| Innodb_buffer_pool_pages_dirty | 0 |
| Innodb_buffer_pool_bytes_dirty | 0 |
| Innodb_buffer_pool_pages_flushed | 1236791 |
| Innodb_buffer_pool_pages_free | 1024 |
| Innodb_buffer_pool_pages_misc | 1 |
| Innodb_buffer_pool_pages_total | 8191 |
| Innodb_buffer_pool_read_ahead_rnd | 0 |
| Innodb_buffer_pool_read_ahead | 384 |
| Innodb_buffer_pool_read_ahead_evicted | 0 |
| Innodb_buffer_pool_read_requests | 390231568 |
| Innodb_buffer_pool_reads | 418780 |
| Innodb_buffer_pool_wait_free | 1132 |
| Innodb_buffer_pool_write_requests | 73595693 |
| Innodb_data_fsyncs | 4378013 |
| Innodb_data_pending_fsyncs | 0 |
| Innodb_data_pending_reads | 0 |
| Innodb_data_pending_writes | 0 |
| Innodb_data_read | 8678395904 |
| Innodb_data_reads | 496835 |
| Innodb_data_writes | 4849865 |
| Innodb_data_written | 48996829184 |
| Innodb_dblwr_pages_written | 1237923 |
| Innodb_dblwr_writes | 24759 |
| Innodb_have_atomic_builtins | ON |
| Innodb_log_waits | 0 |
| Innodb_log_write_requests | 15081412 |
| Innodb_log_writes | 4065255 |
| Innodb_os_log_fsyncs | 4068937 |
| Innodb_os_log_pending_fsyncs | 0 |
| Innodb_os_log_pending_writes | 0 |
| Innodb_os_log_written | 8431348224 |
| Innodb_page_size | 16384 |
| Innodb_pages_created | 325432 |
| Innodb_pages_read | 529553 |
| Innodb_pages_written | 1237923 |
| Innodb_row_lock_current_waits | 0 |
| Innodb_row_lock_time | 0 |
| Innodb_row_lock_time_avg | 0 |
| Innodb_row_lock_time_max | 0 |
| Innodb_row_lock_waits | 0 |
| Innodb_rows_deleted | 409004 |
| Innodb_rows_inserted | 1185998 |
| Innodb_rows_read | 573632779 |
| Innodb_rows_updated | 4000004 |
| Innodb_num_open_files | 9 |
| Innodb_truncated_status_writes | 0 |
| Innodb_available_undo_logs | 128 |
| Key_blocks_not_flushed | 0 |
| Key_blocks_unused | 6698 |
| Key_blocks_used | 4 |
| Key_read_requests | 36 |
| Key_reads | 4 |
| Key_write_requests | 27 |
| Key_writes | 12 |
| Last_query_cost | 0.000000 |
| Last_query_partial_plans | 0 |
| Max_used_connections | 152 |
| Not_flushed_delayed_rows | 0 |
| Open_files | 46 |
| Open_streams | 0 |
| Open_table_definitions | 81 |
| Open_tables | 90 |
| Opened_files | 132390 |
| Opened_table_definitions | 0 |
| Opened_tables | 0 |
| Performance_schema_accounts_lost | 0 |
| Performance_schema_cond_classes_lost | 0 |
| Performance_schema_cond_instances_lost | 0 |
| Performance_schema_digest_lost | 0 |
| Performance_schema_file_classes_lost | 0 |
| Performance_schema_file_handles_lost | 0 |
| Performance_schema_file_instances_lost | 41976 |
| Performance_schema_hosts_lost | 0 |
| Performance_schema_locker_lost | 0 |
| Performance_schema_mutex_classes_lost | 0 |
| Performance_schema_mutex_instances_lost | 0 |
| Performance_schema_rwlock_classes_lost | 0 |
| Performance_schema_rwlock_instances_lost | 0 |
| Performance_schema_session_connect_attrs_lost | 0 |
| Performance_schema_socket_classes_lost | 0 |
| Performance_schema_socket_instances_lost | 0 |
| Performance_schema_stage_classes_lost | 0 |
| Performance_schema_statement_classes_lost | 0 |
| Performance_schema_table_handles_lost | 0 |
| Performance_schema_table_instances_lost | 0 |
| Performance_schema_thread_classes_lost | 0 |
| Performance_schema_thread_instances_lost | 0 |
| Performance_schema_users_lost | 0 |
| Prepared_stmt_count | 0 |
| Qcache_free_blocks | 1 |
| Qcache_free_memory | 1031360 |
| Qcache_hits | 0 |
| Qcache_inserts | 0 |
| Qcache_lowmem_prunes | 0 |
| Qcache_not_cached | 2269633 |
| Qcache_queries_in_cache | 0 |
| Qcache_total_blocks | 1 |
| Queries | 3450957 |
| Questions | 6 |
| Select_full_join | 0 |
| Select_full_range_join | 0 |
| Select_range | 0 |
| Select_range_check | 0 |
| Select_scan | 0 |
| Slave_heartbeat_period |
| | Slave_last_heartbeat |
| | Slave_open_temp_tables | 0 |
| Slave_received_heartbeats |
| | Slave_retried_transactions |
| | Slave_running | OFF |
| Slow_launch_threads | 6 |
| Slow_queries | 0 |
| Sort_merge_passes | 0 |
| Sort_range | 0 |
| Sort_rows | 0 |
| Sort_scan | 0 |
| Ssl_accept_renegotiates | 0 |
| Ssl_accepts | 0 |
| Ssl_callback_cache_hits | 0 |
| Ssl_cipher ||
| Ssl_cipher_list ||
| Ssl_client_connects | 0 |
| Ssl_connect_renegotiates | 0 |
| Ssl_ctx_verify_depth | 0 |
| Ssl_ctx_verify_mode | 0 |
| Ssl_default_timeout | 0 |
| Ssl_finished_accepts | 0 |
| Ssl_finished_connects | 0 |
| Ssl_server_not_after ||
| Ssl_server_not_before ||
| Ssl_session_cache_hits | 0 |
| Ssl_session_cache_misses | 0 |
| Ssl_session_cache_mode | NONE |
| Ssl_session_cache_overflows | 0 |
| Ssl_session_cache_size | 0 |
| Ssl_session_cache_timeouts | 0 |
| Ssl_sessions_reused | 0 |
| Ssl_used_session_cache_entries | 0 |
| Ssl_verify_depth | 0 |
| Ssl_verify_mode | 0 |
| Ssl_version | |
| Table_locks_immediate | 3112087 |
| Table_locks_waited | 0 |
| Table_open_cache_hits | 0 |
| Table_open_cache_misses | 0 |
| Table_open_cache_overflows | 0 |
| Tc_log_max_pages_used | 0 |
| Tc_log_page_size | 0 |
| Tc_log_page_waits | 0 |
| Threads_cached | 9 |
| Threads_connected | 7 |
| Threads_created | 1088 |
| Threads_running | 1 |
| Uptime | 703703 |
| Uptime_since_flush_status | 703703 |
+-----------------------------------------------+-------------+

 

データベース使用量確認

show table status;

OR

select table_schema, sum(data_length+index_length) /1024 /1024 as MB from information_schema.tables  group by table_schema order by sum(data_length+index_length) desc;

 

テーブル使用量確認

select table_name, engine, table_rows as tbl_rows, avg_row_length as rlen,   floor((data_length+index_length)/1024/1024) as allMB,   floor((data_length)/1024/1024) as dMB,   floor((index_length)/1024/1024) as iMB   from information_schema.tables   where table_schema=database()   order by (data_length+index_length) desc;

 

Innodbのステータス

show engine innodb status;

 

+--------+------+----------------------------------------------------------------------------------- | Type   | Name | Status                                                                             +--------+------+----------------------------------------------------------------------------------- | InnoDB |      |  ===================================== 2014-01-30 17:51:37 7f6911898700 INNODB MONITOR OUTPUT ===================================== Per second averages calculated from the last 26 seconds ----------------- BACKGROUND THREAD ----------------- srv_master_thread loops: 15249 srv_active, 0 srv_shutdown, 262158 srv_idle srv_master_thread log flush and writes: 277407 ---------- SEMAPHORES ---------- OS WAIT ARRAY INFO: reservation count 1278141 OS WAIT ARRAY INFO: signal count 1226784 Mutex spin waits 1063192, rounds 31958120, OS waits 1060896 RW-shared spins 161488, rounds 5002921, OS waits 157962 RW-excl spins 31095, rounds 1778537, OS waits 55628 Spin rounds per wait: 30.06 mutex, 30.98 RW-shared, 57.20 RW-excl ------------ TRANSACTIONS ------------ Trx id counter 6805589 Purge done for trx's n:o < 6805587 undo n:o < 0 state: running but idle History list length 1551 LIST OF TRANSACTIONS FOR EACH SESSION: ---TRANSACTION 0, not started MySQL thread id 51524, OS thread handle 0x7f6911898700, query id 3450930 localhost root init show engine innodb status -------- FILE I/O -------- I/O thread 0 state: waiting for i/o request (insert buffer thread) I/O thread 1 state: waiting for i/o request (log thread) I/O thread 2 state: waiting for i/o request (read thread) I/O thread 3 state: waiting for i/o request (read thread) I/O thread 4 state: waiting for i/o request (read thread) I/O thread 5 state: waiting for i/o request (read thread) I/O thread 6 state: waiting for i/o request (write thread) I/O thread 7 state: waiting for i/o request (write thread) I/O thread 8 state: waiting for i/o request (write thread) I/O thread 9 state: waiting for i/o request (write thread) Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,  ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0 Pending flushes (fsync) log: 0; buffer pool: 0 496835 OS file reads, 4849865 OS file writes, 4378013 OS fsyncs 0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s ------------------------------------- INSERT BUFFER AND ADAPTIVE HASH INDEX ------------------------------------- Ibuf: size 1, free list len 2508, seg size 2510, 223697 merges merged operations:  insert 818574, delete mark 1173912, delete 540989 discarded operations:  insert 0, delete mark 2734, delete 616 Hash table size 276671, node heap has 1 buffer(s) 0.00 hash searches/s, 0.00 non-hash searches/s --- LOG --- Log sequence number 6351627995 Log flushed up to   6351627995 Pages flushed up to 6351627995 Last checkpoint at  6351627995 0 pending log writes, 0 pending chkp writes 4067643 log i/o's done, 0.00 log i/o's/second ---------------------- BUFFER POOL AND MEMORY ---------------------- Total memory allocated 137363456; in additional pool allocated 0 Dictionary memory allocated 67836 Buffer pool size   8191 Free buffers       1024 Database pages     7166 Old database pages 2625 Modified db pages  0 Pending reads 0 Pending writes: LRU 0, flush list 0, single page 0 Pages made young 1550487, not young 4767512 0.00 youngs/s, 0.00 non-youngs/s Pages read 529553, created 325432, written 1237923 0.00 reads/s, 0.00 creates/s, 0.00 writes/s No buffer pool page gets since the last printout Pages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/s LRU len: 7166, unzip_LRU len: 0 I/O sum[0]:cur[0], unzip sum[0]:cur[0] -------------- ROW OPERATIONS -------------- 0 queries inside InnoDB, 0 queries in queue 0 read views open inside InnoDB Main thread process no. 20081, id 140089328961280, state: sleeping Number of rows inserted 1185998, updated 4000004, deleted 409004, read 573632779 0.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s ---------------------------- END OF INNODB MONITOR OUTPUT ============================  | +--------+------+-----------------------------------------------------------------------------------

 

テーブルステータス

テーブルに関する情報を表示する

show table status [from <データベース名>] [like <テーブル名>] \G



mysql> show table status from mysql like 'user'\G *************************** 1. row ***************************            Name: user          Engine: MyISAM         Version: 10      Row_format: Dynamic            Rows: 3  Avg_row_length: 53     Data_length: 328 Max_data_length: 281474976710655    Index_length: 2048       Data_free: 168  Auto_increment: NULL     Create_time: 2014-01-21 21:21:36     Update_time: 2014-01-21 21:31:58      Check_time: NULL       Collation: utf8_bin        Checksum: NULL  Create_options:         Comment: Users and global privileges 1 row in set (0.00 sec)



 

プロセス

実行中のクエリ一覧表示

show processlist;

※見切れる場合

show full processlist;

各項目について

参考:https://dev.mysql.com/doc/refman/5.6/ja/show-processlist.html

 

プロセスの検索

プロセスはinformation_schemaテーブルより参照できるので、下記のようにwhere条件を指定できる。

select * from information_schema.PROCESSLIST where XXX order by XXX\G

 

実行中のクエリの強制終了

kill <プロセスID>;

 

ファイルからロード

 

load data




サーバ設定


設定ファイルや起動オプションの他、サーバ稼働中にコマンドによる設定変更が可能である。

セッション変数設定



set [session] <変数>[=<値>];


セッション変数確認



show [session] variables;



グローバル変数設定

 

set lobal <変数>=<値>;

 

グローバル変数確認

全ての変数を表示する。

show global variables;

一部の変数のみを表示する。

show global variables  where Variable_name like '%<検索変数名>%';

 

ユーザ変数

ユーザ変数という、SQL文中に使用することができる変数を定義することができる。
ユーザ変数は変数名の前に @ を付けることで、定義、設定、参照が可能。

set @<変数>=<値>;

 

データベース操作

データベース作成

create database <DB名> [default charset=<文字コード>];

 

データベース削除

drop database <DB名>;

 

ユーザ操作

ユーザ作成



権限の確認

show grants for <ユーザ名>@<接続元ホスト>;


権限削除

revoke <権限> on <DB名>.<テーブル名> from <ユーザ名>@<接続元ホスト>;


テーブル操作

テーブル作成

create table <テーブル名> (<列名> <列型> [オプション] [, ...]);

 

テーブルデータ削除

truncate table <テーブル名>;

 

テーブル定義確認

 

テーブル情報確認

 

 

主キーの追加

alter table <テーブル名> add primary key(<列名> [, ...]);

 

インデックスの作成

create [unique] index <インデックス名> on <テーブル名>(<列名> [, ...]);

 

インデックスの削除

drop index <インデックス名> on <テーブル名>;

 

インデックスの修正

alter table <テーブル名> drop index <インデックス名>(<列名> [, ...]), add index <インデックス名>(<列名> [, ...]);

 

インデックスの確認

show index from <テーブル名>;

インデックスのカーディナリティがNULLの場合、次のコマンドを先に実行する。

analyze table <テーブル名>;

※analyze tableはMyISAMでは全行をリードロック、InnoDBではランダムに10行更新ロックされるので注意

テーブルの変更

alter table <テーブル名> add <列名> <列型> [(first | after) <列名>]; alter table <テーブル名> modify <列名> <列型> [(first | after) <列名>]; alter table <テーブル名> engine = <ストレージエンジン名>; alter table <テーブル名> drop primary key;

 

列名の変更

alter table <テーブル名> change <列名> <新列名> <データ型>;

 

列の型の変更

列の型を変更する。文字列型の文字列長を変更することも可能。

alter table <テーブル名> modify <列名> <データ型>;

 

テーブルの削除

 

drop table <テーブル名>;

 

断片化の確認

 

show table status from <テーブル名>;

Data_free値を確認する。値が大きいほど断片化している。

断片化の解消

 

optimize table <テーブル名>;

 

パーティション


パーティションを作成した場合、パーティション条件に一致しないデータを挿入しようとするとエラーが出る。

パーティションの作成


パーティション列には列名のほか、関数(YEAR()等)や四則演算など使用できる。
例えばDate型はRangeパーティションで使用できないので、TO_DAYS()関数で数値に直す必要がある。
パーティション列は主キーに含まれる必要がある。

 

 

 

パーティションを後から作成

 

 

 

 

パーティションの追加


※データは再配置される

 

 

パーティションの削除

 

 

 

パーティションの停止

 

alter table <テーブル名> remove partitioning;

 

パーティションのメンテナンス

 

 

 

 

 

 

SELECT

 

ファイルへ書き出し

 

select * into outfile '<パス>' [fields <オプション>] from <テーブル>;

 

INSERT

 

バルクインサート



ファイルからロード

 

load data infile



SELECT





 

デフォルトデータベースの変更

 

use <DB名>



サーバ設定


setコマンドはレプリケーションされない

set session set global

 

実行計画(EXPLAIN)


参考:http://dev.mysql.com/doc/refman/5.1/ja/explain.html

 

 































オプション設定


以下では必須ではない、用件毎に応じた設定について記載する

セキュリティ


セキュリティを高める設定を記載する

mysqlユーザのログイン不可


MySQLインストール時に勝手にMySQL起動用の”mysql”ユーザを作成してくれる。
ただし、デフォルトでは”mysql”ユーザはログイン可能となっているが、
ログインする必要はないので、ログインできないように変更する。

 

[root@main1 ~]# cat /etc/passwd | grep mysql mysql:x:498:498:MySQL server:/var/lib/mysql:/bin/bash

 

 

usermod -s /sbin/nologin mysql

 

 

[root@main1 ~]# cat /etc/passwd | grep mysql mysql:x:498:498:MySQL server:/var/lib/mysql:/sbin/nologin




chroot




selinux





ツール

 

mysql


MySQLに同梱される標準的なCLI対話クライアント。
直接クエリを実行するとこともできる。

使用方法





組み込みコマンド






mysqladmin


MySQLの管理操作を行うことができるクライアントツール

使用方法



 

mysqladmin -h <ホスト名> -u <ユーザ名> -p<パスワード> [オプション] <コマンド> [コマンド引数]









perror


MySQLに同梱されているエラーコードの辞書ツール。
引数にエラーコードの数字を与えることで、そのエラーの意味を表示することができる。
エラーコードは複数同時に与えることができる。

 

[root@mysql1 ~]# perror 1 10 35 OS error code   1:  Operation not permitted OS error code  10:  No child processes OS error code  35:  Resource deadlock avoided






mysqlslap


検査にはmysqlslapデータベースが必要だが、オプションにより検査時に作成することも可能。

 

mysql create database mysqlslap;



オプション


参考:http://dev.mysql.com/doc/refman/5.1-olh/ja/mysqlslap.html












実行例



 

mysqlslap -h XXX -u XXX --password=XXX -v -v -c 10 -a --auto-generate-sql-execute-number=100



 

Warning: Using a password on the command line interface can be insecure. Building Create Statements for Auto Building Query Statements for Auto Parsing engines to use. Starting Concurrency Test Loading Pre-data Generating primary key list Generating stats Benchmark         Average number of seconds to run all queries: 0.790 seconds         Minimum number of seconds to run all queries: 0.790 seconds         Maximum number of seconds to run all queries: 0.790 seconds         Number of clients running queries: 10         Average number of queries per client: 100



 

mysqlslap -h XXX -u XXX --password=XXX -v -v -v -c 10 -q "select * from DB1.TABLE1;" --create-schema=DB1



sql-bench


MySQLインストール時に同時にインストールされるベンチマーク用のツール
使用時にカレントディレクトリを以下に変更する必要がある。

cd /usr/local/mysql/sql-bench/


試験では作成済みのデータベースを使用するので、テスト用のデータベースがなければ、事前に作成する必要がある。
テーブルは不要。デフォルトではtestデータベースが使用されるが、任意のものに変更可能。

参考:http://dev.mysql.com/doc/refman/5.1/ja/mysql-benchmarks.html


関連パッケージのインストール



yum install perl-DBI yum install perl-DBD-MySQL



全てのベンチマーク実行


run-all-testsが全てのベンチマークを実行するツールである。

perl run-all-tests [オプション]


 

--<オプション名>=<値>

 

 

 

 

 



 

[root@mysql1 sql-bench]# perl run-all-tests --database=test1 Benchmark DBD suite: 2.15 Date of test:        2014-01-28 11:44:47 Running tests on:    Linux 2.6.32-358.el6.x86_64 x86_64 Arguments:            Comments:             Limits from:          Server version:      MySQL 5.6.15 Optimization:        None Hardware:             alter-table: Total time: 80 wallclock secs ( 0.05 usr  0.04 sys +  0.00 cusr  0.00 csys =  0.09 CPU) ATIS: Total time: 32 wallclock secs ( 2.12 usr  0.15 sys +  0.00 cusr  0.00 csys =  2.27 CPU) big-tables: Total time: 12 wallclock secs ( 0.96 usr  0.19 sys +  0.00 cusr  0.00 csys =  1.15 CPU) connect: Total time: 54 wallclock secs (14.01 usr  6.95 sys +  0.00 cusr  0.00 csys = 20.96 CPU) create: Total time: 9372 wallclock secs ( 6.00 usr  1.39 sys +  0.00 cusr  0.00 csys =  7.39 CPU) insert: Total time: 6469 wallclock secs (137.47 usr 20.25 sys +  0.00 cusr  0.00 csys = 157.72 CPU) select: Total time: 177 wallclock secs (12.28 usr  1.64 sys +  0.00 cusr  0.00 csys = 13.92 CPU) transactions: Test skipped because the database doesn't support transactions wisconsin: Total time: 85 wallclock secs ( 1.74 usr  0.36 sys +  0.00 cusr  0.00 csys =  2.10 CPU) All 9 test executed successfully Totals per operation: Operation             seconds     usr     sys     cpu   tests alter_table_add                       47.00    0.02    0.00    0.02     100  alter_table_drop                      26.00    0.01    0.00    0.01      91  connect                                4.00    1.48    0.64    2.12   10000  connect+select_1_row                   5.00    1.67    0.75    2.42   10000  connect+select_simple                  4.00    1.60    0.73    2.33   10000  count                                  6.00    0.01    0.00    0.01     100  count_distinct                         3.00    0.08    0.01    0.09    1000  count_distinct_2                       7.00    0.11    0.01    0.12    1000  count_distinct_big                     7.00    1.43    0.00    1.43     120  count_distinct_group                   6.00    0.23    0.02    0.25    1000  count_distinct_group_on_key            5.00    0.10    0.02    0.12    1000  count_distinct_group_on_key_parts      5.00    0.24    0.01    0.25    1000  count_distinct_key_prefix              2.00    0.08    0.00    0.08    1000  count_group_on_key_parts               4.00    0.21    0.02    0.23    1000  count_on_key                          38.00    2.98    0.56    3.54   50100  create+drop                          496.00    1.70    0.38    2.08   10000  create_MANY_tables                   431.00    1.15    0.25    1.40   10000  create_index                           1.00    0.00    0.00    0.00       8  create_key+drop                     8076.00    1.96    0.38    2.34   10000  create_table                           1.00    0.01    0.00    0.01      31  delete_all_many_keys                1103.00    0.01    0.00    0.01       1  delete_big                             0.00    0.00    0.00    0.00       1  delete_big_many_keys                1102.00    0.01    0.00    0.01     128  delete_key                            18.00    0.26    0.05    0.31   10000  delete_range                           3.00    0.00    0.00    0.00      12  drop_index                             0.00    0.00    0.00    0.00       8  drop_table                             1.00    0.00    0.00    0.00      28  drop_table_when_MANY_tables          280.00    0.72    0.16    0.88   10000  insert                               962.00    8.88    5.00   13.88  350768  insert_duplicates                      9.00    2.19    0.33    2.52  100000  insert_key                           867.00    5.43    1.03    6.46  100000  insert_many_fields                     8.00    0.11    0.03    0.14    2000  insert_select_1_key                    3.00    0.00    0.00    0.00       1  insert_select_2_keys                   3.00    0.00    0.00    0.00       1  min_max                                3.00    0.01    0.00    0.01      60  min_max_on_key                        11.00    4.17    0.77    4.94   85000  multiple_value_insert                  3.00    0.12    0.01    0.13  100000  once_prepared_select                  12.00    2.36    0.86    3.22  100000  order_by_big                           5.00    4.06    0.00    4.06      10  order_by_big_key                       5.00    4.53    0.00    4.53      10  order_by_big_key2                      5.00    4.23    0.00    4.23      10  order_by_big_key_desc                  6.00    4.43    0.00    4.43      10  order_by_big_key_diff                  5.00    4.11    0.00    4.11      10  order_by_big_key_prefix                5.00    4.26    0.00    4.26      10  order_by_key2_diff                     0.00    0.38    0.00    0.38     500  order_by_key_prefix                    0.00    0.20    0.00    0.20     500  order_by_range                         1.00    0.20    0.00    0.20     500  outer_join                             8.00    0.00    0.00    0.00      10  outer_join_found                       8.00    0.00    0.00    0.00      10  outer_join_not_found                   7.00    0.00    0.00    0.00     500  outer_join_on_key                      9.00    0.00    0.00    0.00      10  prepared_select                       13.00    5.87    0.00    5.87  100000  select_1_row                           8.00    1.58    0.77    2.35  100000  select_1_row_cache                     7.00    1.46    0.81    2.27  100000  select_2_rows                          8.00    1.57    0.82    2.39  100000  select_big                             5.00    4.69    0.01    4.70      80  select_big_str                         2.00    0.61    0.26    0.87   10000  select_cache                          29.00    0.72    0.02    0.74   10000  select_cache2                         29.00    0.71    0.08    0.79   10000  select_column+column                   8.00    1.51    0.78    2.29  100000  select_diff_key                        1.00    0.03    0.00    0.03     500  select_distinct                        1.00    0.32    0.00    0.32     800  select_group                           6.00    0.29    0.01    0.30    2911  select_group_when_MANY_tables         89.00    0.47    0.18    0.65   10000  select_join                            0.00    0.14    0.00    0.14     100  select_key                            26.00   10.64    1.78   12.42  200000  select_key2                           28.00   10.25    1.99   12.24  200000  select_key2_return_key                27.00   10.09    1.90   11.99  200000  select_key2_return_prim               29.00   10.32    1.81   12.13  200000  select_key_prefix                     29.00   10.25    1.15   11.40  200000  select_key_prefix_join                 2.00    0.85    0.00    0.85     100  select_key_return_key                 25.00   10.32    1.89   12.21  200000  select_many_fields                     4.00    0.85    0.16    1.01    2000  select_range                          11.00    1.66    0.01    1.67     410  select_range_key2                      3.00    1.08    0.09    1.17   25010  select_range_prefix                    2.00    1.03    0.10    1.13   25010  select_simple                          4.00    1.28    0.71    1.99  100000  select_simple_cache                    4.00    1.25    0.68    1.93  100000  select_simple_join                     0.00    0.16    0.00    0.16     500  update_big                            30.00    0.01    0.00    0.01      10  update_of_key                        164.00    1.70    0.28    1.98   50000  update_of_key_big                     12.00    0.02    0.01    0.03     501  update_of_primary_key_many_keys     1938.00    0.00    0.02    0.02     256  update_with_key                      881.00    9.34    1.67   11.01  300000  update_with_key_prefix               303.00    5.01    0.83    5.84  100000  wisc_benchmark                         1.00    0.82    0.00    0.82     114  TOTALS                              17355.00  172.64   30.84  203.48 3425950 





mysqldump


MySQLのデータベース・テーブルのバックアップツール。
標準出力に出力するので、ファイルへリダイレクトする

マニュアル

使用方法



 

mysqldump [オプション] (<データベース名> [テーブル名] | --databases) > <ファイル名>

 

 

mysql -u <ユーザ名> -p<パスワード> <データベース名> < <ファイル名>


※データベースは事前に作成しておく。
※データベース全体をリストアする場合はデータベース名の指定は不要。
※先にテーブル作成をしておく場合はエラーを無視する-fオプションを使用してリストアする。



 

mysqlshow


データベースやテーブル、インデックスなどの定義情報を出力する

mysqlcheck


テーブルデータの検査や修復、最適化を行う。


ダウンロードツール

 

MySQL Administrator


MySQL Workbenchに置き換わった、旧公式の管理系GUIツール。

MySQL Query Browser


MySQL Workbenchに置き換わった、旧公式のSQL操作系GUIツール。

MySQL Workbench


MySQL WorkbenchとはMySQL公式の管理ツールでPC上で動作するGUIツールである。
実行中のSQLの監視やSQLのExplainの実行など、パフォーマンスチューニングに使用できる。



MySQLサーバへPCは直接接続可能か、SSH接続可能なサーバから直接接続可能な必要がある。


アカウント作成


リモートから接続可能な管理者アカウントがない場合は作成する。
ユーザ作成

# 参考 grant all on *.* to admin identified by "password";



管理データベース追加


ホーム画面からMySQL Connectionsを作成する



mMeasure



mMeasureは、MySQLの状態を常時測定し、MySQLのチューニングポイントをアドバイスする、MySQL専用モニタリングソフトです。 MySQLの主要なサーバー変数やステータスは、時/日/週/月/年の単位でビジュアルにグラフ化され、ブラウザで参照することができます。 「クエリーキャッシュ使用率」や「接続数」といった測定値が、あらかじめ設定されたしきい値を超えた場合、 MySQLをチューニングするためのアドバイスである「チューニングアドバイス」を表示します。 同時に、チューニングアドバイスは「アラートメール」で管理者宛てにメール送信されますので、 MySQLのチューニングが必要なタイミングが自動的に分かるという特徴を持っています。


http://mmeasure.sourceforge.jp/

MySQL5.1以降はサポートしておらず、動作させるのに何らかの手を加える必要があるらしい。


mytop


mytopはtopコマンドに似た表示形式を持つツールで、
MySQLのスレッドの状態を出力する。
http://jeremy.zawodny.com/mysql/mytop/
※MySQL 4.Xとなっているが、5系も動作する
なお、AWSではパッケージが提供されている。

インストール

 

  1. 関連パッケージをインストールする
    yum install perl-TermReadKey perl-DBI perl-DBD-MySQL perl-ExtUtils-MakeMaker
  2. ソースコードをダウンロードする
    wget http://jeremy.zawodny.com/mysql/mytop/mytop-1.6.tar.gz
  3. 展開する
    tar xvzf mytop-*.tar.gz cd mytop-*
  4. インストールする
    perl Makefile.PL make make install
  5. そのままでは動作しないので、修正する
    chmod u+w `which mytop` vi `which mytop`
    次の行を#コメントアウトする
        "long|!"              => \$config{long_nums},
    権限を戻す。
    chmod 555 `which mytop`
  6. 接続確認する
    mytop -h <ホスト名> -d <データベース名> -u <ユーザ名> -p <パスワード>
    ローカルホスト宛の場合は、以下。
    mytop -S <ソケットファイルパス> -d <データベース名> -u <ユーザ名> -p <パスワード>
  7. 不要なファイルを削除する
    cd ../ rm -rf mytop-*

 

使用方法





設定ファイル



~/.mytop

上記のパスにファイルを置くことで、設定を実行時に読み込ませることができる。
書式は以下のとおり。

user=root
pass=
host=localhost
db=test
delay=5
port=3306
socket=
batchmode=0
header=1
color=1
idle=1


実行結果例



       Copyright (C) 2000-2001, Jeremy D. Zawodny. MySQL on localhost (5.6.15)                                                                                                                                  up 6+20:20:35 [10:45:10]  Queries: 9.0    qps:    0 Slow:     0.0         Se/In/Up/De(%):    00/00/00/00              qps now:    0 Slow qps: 0.0  Threads:    9 (   1/   0) 00/00/00/00  Key Efficiency: 88.9%  Bps in/out:   0.0/  0.1   Now in/out:   7.0/ 1.6k       Id      User         Host/IP         DB      Time    Cmd Query or State       --      ----         -------         --      ----    --- ----------    30080      root       localhost      mysql         0  Query show full processlist    30078      root localhost:49955                    8  Sleep    30079      root localhost:49956                    8  Sleep    30076      root localhost:49953                 1210  Sleep    30077      root localhost:49954                 1210  Sleep    30054      root localhost:49945                57548  Sleep    30055      root localhost:49946                57548  Sleep    30061      root localhost:49952                58608  Sleep    30056      root localhost:49947                70138  Sleep



Maatkit


いくつかの管理ツールが含まれるツールキット

mysqltuner


チューニングすべきポイントを検出するツール

以下からダウンロードするかそのままコピーペーストするだけで動作する。
https://raw.github.com/major/MySQLTuner-perl/master/mysqltuner.pl

実行結果例



[root@mysql1 ~]# perl mysqltuner.pl  >>  MySQLTuner 1.2.0 - Major Hayden <major@mhtx.net>  >>  Bug reports, feature requests, and downloads at http://mysqltuner.com/  >>  Run with '--help' for additional options and output filtering [!!] Successfully authenticated with no password - SECURITY RISK! -------- General Statistics -------------------------------------------------- [--] Skipped version check for MySQLTuner script [OK] Currently running supported MySQL version 5.6.15 [OK] Operating on 64-bit architecture -------- Storage Engine Statistics ------------------------------------------- [--] Status: +Archive -BDB -Federated +InnoDB -ISAM -NDBCluster [--] Data in PERFORMANCE_SCHEMA tables: 0B (Tables: 52) [!!] InnoDB is enabled but isn't being used [OK] Total fragmented tables: 0 -------- Security Recommendations  ------------------------------------------- [!!] User 'root@127.0.0.1' has no password set. [!!] User 'root@::1' has no password set. [!!] User 'root@localhost' has no password set. -------- Performance Metrics ------------------------------------------------- [--] Up for: 6d 3h 18m 58s (3M q [6.382 qps], 30K conn, TX: 1B, RX: 217M) [--] Reads / Writes: 68% / 32% [--] Total buffers: 169.0M global + 1.1M per thread (151 max threads) [OK] Maximum possible memory usage: 338.9M (34% of installed RAM) [OK] Slow queries: 0% (153/3M) [OK] Highest usage of available connections: 4% (7/151) [OK] Key buffer size / total MyISAM indexes: 8.0M/97.0K [!!] Key buffer hit rate: 88.9% (36 cached / 4 reads) [!!] Query cache efficiency: 0.0% (0 cached / 2M selects) [OK] Query cache prunes per day: 0 [OK] Sorts requiring temporary tables: 3% (200 temp sorts / 5K sorts) [OK] Temporary tables created on disk: 0% (2 on disk / 13K total) [OK] Thread cache hit rate: 99% (7 created / 30K connections) [OK] Open file limit used: 0% (0/5K) [OK] Table locks acquired immediately: 100% (3M immediate / 3M locks) -------- Recommendations ----------------------------------------------------- General recommendations:     Add skip-innodb to MySQL configuration to disable InnoDB Variables to adjust:     query_cache_limit (> 1M, or use smaller result sets)





sysbench


ベンチマークツール

http://sysbench.sourceforge.net/docs/

インストール


MySQLのソースコードによるインストールを行う
最新版のソースコードのURLを調べる
http://dev.mysql.com/downloads/benchmarks.html

  1. ダウンロードする
    wget http://downloads.mysql.com/source/sysbench-0.4.12.5.tar.gz
  2. 展開する
    gunzip -c sysbench-*.tar.gz | tar zxv cd sysbench-*
  3. コンパイル設定を行う
    ./configure --with-mysql-libs=/usr/local/mysql/lib --prefix=/usr/local/sysbench-0.4.12.5
  4. インストールする
    make make install
  5. 共有ライブラリの変更を行う
    1. 現在のライブラリを確認する
      ldd `which sysbench` # 以下の場合変更が必要 # libmysqlclient.so.18 => /usr/lib64/mysql/libmysqlclient.so.18
    2. 設定ファイルを確認する
      ls /etc/ld.so.conf.d/mysql*
    3. 全てリネームする
      mv /etc/ld.so.conf.d/mysqlXXX.conf /etc/ld.so.conf.d/mysqlXXX.conf.unused
    4. 新しいconfを作成する
      echo /usr/local/mysql/lib > /etc/ld.so.conf.d/mysql.conf
    5. 更新する
      ldconfig
    6. 変更されていることを確認する
      ldd `which sysbench` # libmysqlclient.so.18 => /usr/local/mysql/lib/libmysqlclient.so.18
  6. リンクを作成する
    ln -s /usr/local/sysbench-0.4.12.5 /usr/local/sysbench ln -s /usr/local/sysbench/bin/sysbench /usr/local/bin/sysbench
  7. パスがない場合、追加する
    which sysbench export PATH=$PATH:/usr/local/bin vi /etc/bashrc # 以下を追記する export PATH=$PATH:/usr/local/bin



オプション


























出力例



sysbench 0.4.13:  multi-threaded system evaluation benchmark Running the test with following options: Number of threads: 50 Additional request validation enabled. Random number generator seed is 0 and will be ignored Doing OLTP test. Running mixed OLTP test Doing read-only test Using Special distribution (12 iterations,  1 pct of values are returned in 75 pct cases) Using "BEGIN" for starting transactions Using auto_inc on the id column Validation mode enabled Using 1 test tables Threads started! Time limit exceeded, exiting... (last message repeated 49 times) Done. OLTP test statistics:     queries performed:         read:                            479612         write:                           0         other:                           68516         total:                           548128     transactions:                        34258  (570.37 per sec.)     deadlocks:                           0      (0.00 per sec.)     read/write requests:                 479612 (7985.12 per sec.)     other operations:                    68516  (1140.73 per sec.) Test execution summary:     total time:                          60.0632s     total number of events:              34258     total time taken by event execution: 3001.8914     per-request statistics:          min:                                 49.77ms          avg:                                 87.63ms          max:                                184.05ms          approx.  95 percentile:             107.49ms Threads fairness:     events (avg/stddev):           685.1600/7.31     execution time (avg/stddev):   60.0378/0.02






OLTPベンチマークの実施例


特定時間の間のクエリー実行回数を調べる

  1. 試験用のデータベースを作成する(2回目以降は不要)
    mysql -h <接続ホスト> -u <ユーザ> -p # mysql内で以下を実行 create database sbtest; exit;
  2. 試験用データを作成する
    sysbench --test=oltp --db-driver=mysql --mysql-host=<接続ホスト> --mysql-user=<ユーザ> --mysql-password=<パスワード> \ --oltp-test-mode=complex --oltp-table-size=150000 --oltp-connect-delay=0 \ --mysql-table-engine=innodb --num-threads=20 --max-time=60 --max-requests=0 prepare
  3. キャッシュにデータを読み込む
    sysbench --test=oltp --db-driver=mysql --mysql-host=<接続ホスト> --mysql-user=<ユーザ> --mysql-password=<パスワード> \ --oltp-test-mode=complex --oltp-table-size=150000 --oltp-connect-delay=0 \ --mysql-table-engine=innodb --num-threads=20 --max-time=60 --max-requests=0 --oltp-read-only run
  4. 試験を実施する
    sysbench --test=oltp --db-driver=mysql --mysql-host=<接続ホスト> --mysql-user=<ユーザ> --mysql-password=<パスワード> \ --oltp-test-mode=complex --oltp-table-size=150000 --oltp-connect-delay=0 \ --mysql-table-engine=innodb --num-threads=20 --max-time=60 --max-requests=0  --num-threads=<スレッド数> run
  5. 試験データを削除する
    sysbench --test=oltp --db-driver=mysql --mysql-host=<接続ホスト> --mysql-user=<ユーザ> --mysql-password=<パスワード> \ --oltp-test-mode=complex --oltp-table-size=150000 --oltp-connect-delay=0 \ --db-ps-mode=disable --mysql-table-engine=innodb --num-threads=20 --max-time=60 --max-requests=0 cleanup


1クライアントホストのスレッド数を400以上にする場合、–db-ps-mode=disableオプションをつけないとエラーが出る可能性がある。


Database Test Suite




Super Smack




tpcc-mysql




innotop

 

インストール



  1. 関連パッケージをインストールする
    yum install perl-DBI perl-DBD-mysql perl-ExtUtils-MakeMaker perl-Time-HiRes perl-TermReadKey -y
  2. 最新版のソースコードのURLを調べる
    http://code.google.com/p/innotop/downloads/list
  3. ダウンロードする
    wget http://innotop.googlecode.com/files/innotop-1.9.1.tar.gz
  4. 展開する
    tar zfvx innotop-* cd innotop-*
  5. インストールする
    perl Makefile.PL make install
  6. インストールされたことを確認する
    which innotop
    ※見つからない場合、/usr/local/binをPATHに追加する。



使用方法



 

innotop -u <username> -p <password> -h <hostname> [オプション]


















Specifies the mode in which innotop should start. Corresponds to the configuration option “mode”.



Enable non-interactive operation. See “NON-INTERACTIVE OPERATION” for more.




 


Don’t read the central configuration file.



In -n mode, write a timestamp either before every screenful of output, or if the option is given twice, at the start of every line. The format is
controlled by the timeformat config variable.








InnoDB Hot Backup

 

Xtra Backup




その他

 

md5sum


md5sumコマンドはファイルのハッシュ値を計算することができる。
テーブルデータファイルのハッシュ値を控えておくことで、更新があった場合に検地できる。

md5sum <ファイル>


定常運用


作業手順の基本は「準備」→「確認1」→「変更1」→「確認1」→「確認2」→「変更2」→「確認2」→…(必要な作業分だけ)…→「最終確認」→「事後作業」である。

管理系

 

ユーザ作成







 

grant <authority> on *.* to <new-user> identified by "<password>"; # 接続元を制限する場合 # grant <authority> on *.* to <new-user>@<srcIP> identified by "<password>"; # <srcIP>にネットワークアドレスを指定する場合、@"192.168.0.0/255.255.255.0" もしくは @192.168.128. のように指定する。



 

# 追加するユーザが存在することを確認する # 設定した権限が付与されていることを確認する show grants for <new-user>;



ユーザ削除



 

# 現在のユーザの確認 select Host,User from mysql.user;



 

# 削除するユーザが存在することを確認する show grants for <new-user>;



 

drop user <user>;



 

# 削除したユーザが存在しないことを確認する show grants for <new-user>;




データベース系

 

データベースの作成



 

# ログインする mysql -h <ホスト名> -u <ユーザ名> -p

 

# 現在のデータベースを確認する show databases;



 

# 作成するデータベースが存在しないことを確認する show create database <new-database>;



 

create database <params>;



 

# 作成するデータベースが存在することを確認する show create database <new-table>;




テーブルの作成



 

# ログインする mysql -h <ホスト名> -u <ユーザ名> -p

 

# テーブル作成するデータベースに接続する use <database>;

 

# 現在のテーブルを確認する show tables;



 

# 現在接続しているデータベースを確認する select database();

 

# 作成するテーブルが存在しないことを確認する show create table <new-table>;



 

create table <params>;



 

# 作成するテーブルが存在することを確認する show create table <new-table>;




テーブルの削除



 

# ログインする mysql -h <ホスト名> -u <ユーザ名> -p

 

# テーブル削除するデータベースに接続する use <database>;

 

# 現在のテーブルを確認する show tables;



 

# 現在接続しているデータベースを確認する select database();

 

# 削除するテーブルが存在することを確認する show create table <new-table>;



 

drop table <params>;



 

# 削除するテーブルが存在しないことを確認する show create table <new-table>;





非定常運用

 

サーバ系

 

レプリケーションの開始


現在レプリケーションを行っていないサーバでレプリケーションを開始する。

InnoDBのリストア


MySQLを停止させた状態で、データファイルをクラッシュ前のものに置き換える。
MySQLを起動させると、自動でバイナリログを読み込んで、未適用のものが反映される。

オンラインバックアップ


mysqldumpを使用する

オフラインバックアップ


データファイルをコピーする

データ系


文字コードの変更
データベースとテーブル、照合順序、データの文字コードを変更する。
InnoDBでは767byteがサポートするインデックスの最大長であり、変更する再に制限を越える可能性があるので、注意する。
なお、utf8mb4を使用する場合、191文字まで。

 

# 作業中、DBへのアクセスを行ってはいけない

 

# ログインする mysql -h <ホスト名> -u <ユーザ名> -p

 

# データベースが変更前の文字コードで定義されていることを確認する show create database <データベース名>; # 必要に応じて以下も実施する show create table <データベース名>.<テーブル名>\G

 

# ログアウトする quit



 

# データベースのバックアップを取得する mysqldump -h <ホスト名> -u <ユーザ名> -p <データベース名> > mysql_dump.old



文字コードの変更



sed "s/<旧文字コード>/<新文字コード>/g" mysql_dump.old > mysql_dump.new # utf8からutf8mb4に変更する場合は正規表現の否定先読みが必要なので、perlで行う # perl -e 'open(F,"mysql_dump.old");while(my$line=<F>){$line=~s/utf8(?!mb4)/utf8mb4/g;print("$line");}' > mysql_dump.new



 

mysqladmin -h <ホスト名> -u <ユーザ名> -p drop <データベース名> # プロンプトに y と答える



 

# データベースの作成 echo "create database <データベース名> character set <新文字コード>;" | mysql -h <ホスト名> -u <ユーザ名> -p

 

# データの投入 mysql -h <ホスト名> -u <ユーザ名> -p venusr_guild1 < mysql_dump.new



 

mysqldump -h <ホスト名> -u <ユーザ名> -p <データベース名> > mysql_dump.result diff mysql_dump.new mysql_dump.result # コメント行の差分は無視する # 万が一、insertステートメント中に差分が発生してしまった場合は、 # --skip-extended-insertオプションを使用してダンプを取得しなおし、 # どこで差分が出たのか確認する



 

# ログインする mysql -h <ホスト名> -u <ユーザ名> -p # データベースが新しい文字コードで定義されていることを確認する show create database <データベース名>; # ログアウトする quit



rm -f mysql_dump.old rm -f mysql_dump.new rm -f mysql_dump.result





障害対応
















パフォーマンスチューニング

テーブルキャッシュ

下記コマンドでステータスを確認する。

show status like 'open%tables';

実行すると以下の2つの値が確認できる。それぞれ次の意味である。

一定期間上記を観察し、以下の場合、table_open_cacheの値を大きくするとパフォーマンスが改善され得る。

なお、table_open_cacheの値は最低でもmax_connectionsと同数にする必要がある。

show global variables like 'max_connections';

 

クエリキャッシュ

コミットの早期化

クエリキャッシュはテーブル変更後に破棄されるが、そのテーブルをコミットするまではキャッシュが再開されることはない。
そのため、長期にわたるトランザクションを避け、早期にコミットするようにしたほうがキャッシュをより有効に活用できる。

 

キャッシュの無効化

クエリキャッシュを有効にするとキャッシュの参照・格納・破棄等で多少オーバーヘッドが発生するので、
更新が多く参照が少ないなどキャッシュヒット率が著しく低い場合は無効にしたほうがよい。

 

大きな結果のキャッシュの無効化

クエリキャッシュを格納するためにMySQLはキャッシュ格納用のメモリブロックを走査しなければならない。
そのため、サイズの大きな結果は小さなものに比べると時間がかかる。また、キャッシュの破棄に関しても同様である。
そこで、結果が大きくなり、かつそれを再利用する可能性が極めて低い場合はそのクエリのキャッシュを無効化するのが良い。

キャッシュサイズの増量

show status;で確認できるQcache_hitsの値が想定より増加しない場合は
キャッシュサイズが不足して破棄されている可能性があるので、
キャッシュサイズを増加させる。


内部一時テーブルのサイズ変更

ステータスを取得し(”show global status;”)、Created_tmp_disk_tablesの値が増大していれば、tmp_table_sizeの値を増やしたほうが良い。
どうしてもメモリが割り当てられなければ、可能であればtmpdirのパスをSSD上にする。


クライアントプログラム

prepared statementの使用

一部の変数部分のみ異なる大量のSQLを発行する場合、prepared statementを使用することで、
通信量や、SQLパースの負荷を削減でき、高速化できる。

ストアドプロシージャ / ストアドファンクションの利用

メリット



デメリット

ストアドファンクションはストアドプロシージャと異なり、値を返すことができるので、他のSQLなどに組み込みその値を利用するといったことができる。

トリガの利用

何らかの処理をデータベースで行った際に別の処理を行いたいとき、トリガを利用できる。
例えば、あるテーブルに変更が発生した際にその変更箇所をログとしてログテーブルに追加するといったことができる。

リードオンリー化

トランザクションをリードオンリーとすることで、高速処理が可能となる。
次のコマンドをトランザクションで最初に実行すると良い。

START TRANSACTION READ ONLY

トランザクションではないコネクションでは使用できない。

遅延INSERT

INSERTを非同期で実行することで、ブロックされることなくプログラム側に処理を戻すことができる。
構文はINSERT DELAYEDである。

ただし、遅延INSERTはMyISAMなどの一部のストレージエンジンでしか対応しておらず、InnoDBでは使用できない。

 

型変換の不使用

数値型に対して、数値をシングルクォーテーションなどで囲った値と比較すると、文字列との比較になるので、一方の型変換が発生する。
型変換によるオーバーヘッドが発生するため、意図的にしろ、型変換は使用すべきではない。
つまり、

select ~ where num = '100';

select ~ where num = 100;

とする。

SQL

インデックスの不使用

バッチ処理などで大量のデータにアクセスする際にはインデックスを使用せずに
テーブルをフルスキャンしたほうが高速な場合がある。
その場合は、ignore indexを指定してインデックスを使用しないようにする。

select * from table1 ignore index(index1) where xxx = n;



テーブル設計

固定長・可変長

可変長のデータを扱う場合、データの断片化が起こり、テーブル容量が大きくなる。
そのため、可変長のデータサイズのバラつきが小さい場合、固定長にすることで断片化が防げる。
また、固定長のほうが処理が高速である。
可変長のデータサイズのバラつきが大きい場合は、可変長のほうが無駄なディスクI/Oが防げるので可変長のほうがよい。

インデックス

インデックス列の並び替え

複数の列からなるインデックスを使用する場合、よりカーディナリティが大きい(より少数に絞り込める)列を
前に持ってくるほうが検索効率が高くなる。


Notice: Trying to get property 'queue' of non-object in /usr/local/wordpress/wp-includes/script-loader.php on line 2876

Warning: Invalid argument supplied for foreach() in /usr/local/wordpress/wp-includes/script-loader.php on line 2876