プロジェクト

全般

プロフィール

CentOS 6でMySQL 56をインストール

はじめに

CentOS 6の標準搭載MySQLはバージョン5.1と少々古く、2013年にリリースされた最新版の5.6を利用することで機能性能向上が期待できます。ストレージエンジンInnoDBの性能向上、オプティマイザの改良(サブクエリ高速化ほか)などがあるようです。

RPMの入手

MySQL公式サイトで、Red Hat Enterprise Linux 6用のバイナリ(RPMパッケージ)が公開されています。
64bit用を入手します。

  • MySQL.jp にアクセスし、[ダウンロード(GA)]タブをクリックし、下の方にあるMySQL Community Edition(GPL)の見出しのしたのリンク"Download from MySQL Developer Zone >>"をクリックします。
  • MySQL Downloadsページが開くので、"MySQL Community Server"のリンクをクリックします。
  • Select Platform欄を"Red Hat Enterprise Linux / Oracle Linux"に切り替えます。
  • "Red Hat Enterprise Linux 6 / Oracle Linux 6(x86,64-bit), RPM Bundleの欄の[Download]ボタンをクリックします。
  • OracleアカウントでLoginするか、画面下の方の"No thanks, just start my download."をクリックします。
    Oracleアカウントでログインすると、アンケート(調査)入力してからのダウンロードとなります。
2014-06-08現在ダウンロードしたバージョンは次です。
  • MySQL-5.6.19-1.el6.x86_64.rpm-bundle.tar

このtarには次のRPMファイルが含まれています。

$ tar tf MySQL-5.6.19-1.el6.x86_64.rpm-bundle.tar 
MySQL-embedded-5.6.19-1.el6.x86_64.rpm
MySQL-devel-5.6.19-1.el6.x86_64.rpm
MySQL-client-5.6.19-1.el6.x86_64.rpm
MySQL-shared-compat-5.6.19-1.el6.x86_64.rpm
MySQL-server-5.6.19-1.el6.x86_64.rpm
MySQL-shared-5.6.19-1.el6.x86_64.rpm
MySQL-test-5.6.19-1.el6.x86_64.rpm

CentOS 6標準MySQLが入っているマシンの更新

既にCentOS 6標準MySQL 5.1がインストールされているマシンにMySQL 5.6をインストールします。

$ rpm -qa|grep mysql
mysql-libs-5.1.73-3.el6_5.x86_64
mysql-5.1.73-3.el6_5.x86_64
mysql-server-5.1.73-3.el6_5.x86_64
mysql-devel-5.1.73-3.el6_5.x86_64

試行1

  • mysqldを停止
    $ sudo service mysqld stop
  • MySQL-client, MySQL-devel, MySQL-server, MySQL-shared-compatをインストール
    $ sudo yum localinstall MySQL-{client,devel,server,shared-compat}-5.6.19-1.el6.x86_64.rpm
      :
    ================================================================================
     Package        Arch   Version        Repository                           Size
    ================================================================================
    Installing:
     MySQL-client   x86_64 5.6.19-1.el6   /MySQL-client-5.6.19-1.el6.x86_64    82 M
         replacing  mysql.x86_64 5.1.73-3.el6_5
     MySQL-devel    x86_64 5.6.19-1.el6   /MySQL-devel-5.6.19-1.el6.x86_64     19 M
         replacing  mysql-devel.x86_64 5.1.73-3.el6_5
     MySQL-server   x86_64 5.6.19-1.el6   /MySQL-server-5.6.19-1.el6.x86_64   233 M
         replacing  mysql-server.x86_64 5.1.73-3.el6_5
     MySQL-shared-compat
                    x86_64 5.6.19-1.el6   /MySQL-shared-compat-5.6.19-1.el6.x86_64
                                                                               11 M
         replacing  mysql-libs.x86_64 5.1.73-3.el6_5
    Installing for dependencies:
     libaio         x86_64 0.3.107-10.el6 base                                 21 k
    
    Transaction Summary
    ================================================================================
    Install       5 Package(s)
      :
    Error in PREIN scriptlet in rpm package MySQL-server-5.6.19-1.el6.x86_64
    
    ******************************************************************
    A MySQL server package (mysql-server-5.1.73-3.el6_5.x86_64) is installed.
    
    The current MySQL server package is provided by a different
    vendor (CentOS) than MySQL AB, Sun Microsystems, Inc., or Oracle and/or its affiliates.
    Some files may be installed to different locations, including log
    files and the service startup script in /etc/init.d/.
    
    Upgrading directly from MySQL 5.1 to MySQL 5.6 may not
    be safe in all cases.  A manual dump and restore using mysqldump is
    recommended.  It is important to review the MySQL manual's Upgrading
    section for version-specific incompatibilities.
    
    A manual upgrade is required.
    
    - Ensure that you have a complete, working backup of your data and my.cnf
      files
    - Shut down the MySQL server cleanly
    - Remove the existing MySQL packages.  Usually this command will
      list the packages you should remove:
      rpm -qa | grep -i '^mysql-'
    
      You may choose to use 'rpm --nodeps -ev <package-name>' to remove
      the package which contains the mysqlclient shared library.  The
      library will be reinstalled by the MySQL-shared-compat package.
    - Install the new MySQL packages supplied by Oracle and/or its affiliates
    - Ensure that the MySQL server is started
    - Run the 'mysql_upgrade' program
    
    This is a brief description of the upgrade process.  Important details
    can be found in the MySQL manual, in the Upgrading section.
    ******************************************************************
    error: %pre(MySQL-server-5.6.19-1.el6.x86_64) scriptlet failed, exit status 1
    error:   install: %pre scriptlet failed (2), skipping MySQL-server-5.6.19-1.el6
      Installing : MySQL-client-5.6.19-1.el6.x86_64                             3/9
      Installing : MySQL-shared-compat-5.6.19-1.el6.x86_64                      4/9
      Installing : MySQL-devel-5.6.19-1.el6.x86_64                              5/9
      Erasing    : mysql-devel-5.1.73-3.el6_5.x86_64                            6/9
      Erasing    : mysql-5.1.73-3.el6_5.x86_64                                  7/9
      Erasing    : mysql-libs-5.1.73-3.el6_5.x86_64                             8/9
      Verifying  : MySQL-devel-5.6.19-1.el6.x86_64                              1/9
      Verifying  : MySQL-shared-compat-5.6.19-1.el6.x86_64                      2/9
      Verifying  : libaio-0.3.107-10.el6.x86_64                                 3/9
      Verifying  : MySQL-client-5.6.19-1.el6.x86_64                             4/9
      Verifying  : mysql-devel-5.1.73-3.el6_5.x86_64                            5/9
      Verifying  : MySQL-server-5.6.19-1.el6.x86_64                             6/9
    mysql-server-5.1.73-3.el6_5.x86_64 was supposed to be removed but is not!
      Verifying  : mysql-server-5.1.73-3.el6_5.x86_64                           7/9
      Verifying  : mysql-5.1.73-3.el6_5.x86_64                                  8/9
      Verifying  : mysql-libs-5.1.73-3.el6_5.x86_64                             9/9
    
    Installed:
      MySQL-client.x86_64 0:5.6.19-1.el6         MySQL-devel.x86_64 0:5.6.19-1.el6
      MySQL-shared-compat.x86_64 0:5.6.19-1.el6
    
    Dependency Installed:
      libaio.x86_64 0:0.3.107-10.el6
    
    Replaced:
      mysql.x86_64 0:5.1.73-3.el6_5          mysql-devel.x86_64 0:5.1.73-3.el6_5
      mysql-libs.x86_64 0:5.1.73-3.el6_5
    
    Failed:
      MySQL-server.x86_64 0:5.6.19-1.el6    mysql-server.x86_64 0:5.1.73-3.el6_5
    
    Complete!
    

と、MySQL-serverのインストールが失敗しました。メッセージにあるとおり、手動でmysql-server-5.1をアンインストールして、再度MySQL-serverをインストールします。

  • mysql-server-5.1のアンインストール
    $ sudo yum erase mysql-server
      :
    ================================================================================
     Package             Arch          Version                Repository       Size
    ================================================================================
    Removing:
     mysql-server        x86_64        5.1.73-3.el6_5         @updates         25 M
    
    Transaction Summary
    ================================================================================
    Remove        1 Package(s)
      :
    $
    
  • MySQL-server-5.6のインストール
    $ sudo yum localinstall MySQL-server-5.6.19-1.el6.x86_64.rpm
      :
    ================================================================================
     Package       Arch    Version         Repository                          Size
    ================================================================================
    Installing:
     MySQL-server  x86_64  5.6.19-1.el6    /MySQL-server-5.6.19-1.el6.x86_64  233 M
    
    Transaction Summary
    ================================================================================
    Install       1 Package(s)
      :
    

/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
character-set-server=utf8
default-storage-engine = InnoDB

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

[mysql]
default-character-set=utf8

mysqlのサービスを起動

$ sudo service mysql start

このあとRedmineを触っている限り、とりあえず動いているようです。

最後に

Linuxディストリビューションは、昨今MySQLからフォークしたMariaDBを採用する動きが広まっています。
Red Hat Enterprise Linuxがバージョン7でMySQLに替えてMariaDBを標準搭載しています。


ほぼ10年前に更新