【5分で！】centOS6.5にMySQLの最新版をyum使ってインストールするぜ


[前回の記事](http://qiita.com/ritukiii/items/cc22efd005a06b8d4a86)でyumの勉強をしたので、ついでにMySQLの最新版を入れてみたいと思います

## Step1. 自分のサーバのOSバージョンを確認しとく

MySQLでは、インストールするyumリポジトリがサーバのOSバージョン毎に用意されてるので、予め確認しておきましょう。

```
# cat /etc/redhat-release
CentOS release 6.5 (Final)
```

私のはcentos 6.5でした。

## step2. MySQLの公式からyumリポジトリを探しに行きます

[mysqlの公式](http://dev.mysql.com/downloads/repo/yum/)に、各OS毎のyumリポジトリがありますので、自分のOSに合うもののダウンロードページへ行きます。

### Downloadボタンをクリック

![download.png](https://qiita-image-store.s3.amazonaws.com/0/23276/3968ae5e-a8bb-68e1-90da-dcfe2e5c265c.png "download.png")

### Loginとか気にせずURLをコピー

![copy url.png](https://qiita-image-store.s3.amazonaws.com/0/23276/9d68efcc-21c6-1c25-7fff-d0978388d3b4.png "copy url.png")


## step3. 公式リポジトリを追加する

```
# yum install http://dev.mysql.com/get/mysql57-community-release-el6-8.noarch.rpm
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
 * base: ftp.iij.ad.jp
 * extras: ftp.iij.ad.jp
 * updates: ftp.iij.ad.jp
Setting up Install Process
mysql57-community-release-el6-8.noarch.rpm                                                                                                        | 8.9 kB     00:00
Examining /var/tmp/yum-root-sWSouw/mysql57-community-release-el6-8.noarch.rpm: mysql57-community-release-el6-8.noarch
Marking /var/tmp/yum-root-sWSouw/mysql57-community-release-el6-8.noarch.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package mysql57-community-release.noarch 0:el6-8 will be installed
--> Processing Conflict: mysql57-community-release-el6-8.noarch conflicts mysql-community-release
No package matched to upgrade: mysql57-community-release
--> Finished Dependency Resolution
Error: mysql57-community-release conflicts with mysql-community-release-el7-5.noarch
 You could try using --skip-broken to work around the problem
 You could try running: rpm -Va --nofiles --nodigest
```
 
おや、なんかすでにあるMySQLと競合したっぽいので、インストール済みのMySQLを確認してみましょう。

```
# yum list installed | grep mysql
mysql-community-common.x86_64
                      5.6.14-3.el6      @mysql-community
mysql-community-devel.x86_64
                      5.6.14-3.el6      @mysql-community
mysql-community-embedded.x86_64
                      5.6.14-3.el6      @mysql-community
mysql-community-embedded-devel.x86_64
                      5.6.14-3.el6      @mysql-community
mysql-community-libs.x86_64
                      5.6.14-3.el6      @mysql-community
mysql-community-libs-compat.x86_64
                      5.6.14-3.el6      @mysql-community
mysql-community-release.noarch
                      el7-5             @/mysql-community-release-el7-5.noarch
php-mysqlnd.x86_64    5.5.16-1.el6.remi.2
```

どうやらすでに色々入ってました。消しちゃいましょう

```
# yum remove mysql*
Loaded plugins: fastestmirror, security
Setting up Remove Process
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-common.x86_64 0:5.6.14-3.el6 will be erased
---> Package mysql-community-devel.x86_64 0:5.6.14-3.el6 will be erased
---> Package mysql-community-embedded.x86_64 0:5.6.14-3.el6 will be erased
---> Package mysql-community-embedded-devel.x86_64 0:5.6.14-3.el6 will be erased
---> Package mysql-community-libs.x86_64 0:5.6.14-3.el6 will be erased
---> Package mysql-community-libs-compat.x86_64 0:5.6.14-3.el6 will be erased
---> Package mysql-community-release.noarch 0:el7-5 will be erased
--> Finished Dependency Resolution

Dependencies Resolved

=========================================================================================================================================================================
 Package                                          Arch                     Version                        Repository                                                Size
=========================================================================================================================================================================
Removing:
 mysql-community-common                           x86_64                   5.6.14-3.el6                   @mysql-community                                         2.1 M
 mysql-community-devel                            x86_64                   5.6.14-3.el6                   @mysql-community                                          19 M
 mysql-community-embedded                         x86_64                   5.6.14-3.el6                   @mysql-community                                          78 M
 mysql-community-embedded-devel                   x86_64                   5.6.14-3.el6                   @mysql-community                                         356 M
 mysql-community-libs                             x86_64                   5.6.14-3.el6                   @mysql-community                                         8.4 M
 mysql-community-libs-compat                      x86_64                   5.6.14-3.el6                   @mysql-community                                         5.3 M
 mysql-community-release                          noarch                   el7-5                          @/mysql-community-release-el7-5.noarch                   4.3 k

Transaction Summary
=========================================================================================================================================================================
Remove        7 Package(s)

Installed size: 469 M
Is this ok [y/N]: y
Downloading Packages:

... 中略　...
Complete!
```

さて、もう公式リポジトリを追加してみましょう。

```
# yum install http://dev.mysql.com/get/mysql57-community-release-el6-8.noarch.rpm
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
 * base: ftp.iij.ad.jp
 * extras: ftp.iij.ad.jp
 * updates: ftp.iij.ad.jp
Setting up Install Process
mysql57-community-release-el6-8.noarch.rpm                                                                                                        | 8.9 kB     00:00
Examining /var/tmp/yum-root-sWSouw/mysql57-community-release-el6-8.noarch.rpm: mysql57-community-release-el6-8.noarch
Marking /var/tmp/yum-root-sWSouw/mysql57-community-release-el6-8.noarch.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package mysql57-community-release.noarch 0:el6-8 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=========================================================================================================================================================================
 Package                                       Arch                       Version                      Repository                                                   Size
=========================================================================================================================================================================
Installing:
 mysql57-community-release                     noarch                     el6-8                        /mysql57-community-release-el6-8.noarch                     8.2 k

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

Total size: 8.2 k
Installed size: 8.2 k
Is this ok [y/N]: y
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : mysql57-community-release-el6-8.noarch                                                                                                                1/1
  Verifying  : mysql57-community-release-el6-8.noarch                                                                                                                1/1

Installed:
  mysql57-community-release.noarch 0:el6-8

Complete!
```

今度は追加出来ました。

追加が完了すると、`mysql-community-server`という名前のパッケージがインストール出来るようになりますので、インストールします。

```
#  yum -y install mysql-community-server
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
 * base: ftp.iij.ad.jp
 * extras: ftp.iij.ad.jp
 * updates: ftp.iij.ad.jp
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-server.x86_64 0:5.7.13-1.el6 will be installed
--> Processing Dependency: mysql-community-common(x86-64) >= 5.7.9 for package: mysql-community-server-5.7.13-1.el6.x86_64
--> Processing Dependency: mysql-community-client(x86-64) >= 5.7.9 for package: mysql-community-server-5.7.13-1.el6.x86_64
--> Running transaction check
---> Package mysql-community-client.x86_64 0:5.7.13-1.el6 will be installed
--> Processing Dependency: mysql-community-libs(x86-64) >= 5.7.9 for package: mysql-community-client-5.7.13-1.el6.x86_64
---> Package mysql-community-common.x86_64 0:5.7.13-1.el6 will be installed
--> Running transaction check
---> Package mysql-community-libs.x86_64 0:5.7.13-1.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=========================================================================================================================================================================
 Package                                         Arch                            Version                                Repository                                  Size
=========================================================================================================================================================================
Installing:
 mysql-community-server                          x86_64                          5.7.13-1.el6                           mysql57-community                          143 M
Installing for dependencies:
 mysql-community-client                          x86_64                          5.7.13-1.el6                           mysql57-community                           22 M
 mysql-community-common                          x86_64                          5.7.13-1.el6                           mysql57-community                          327 k
 mysql-community-libs                            x86_64                          5.7.13-1.el6                           mysql57-community                          2.1 M

Transaction Summary
=========================================================================================================================================================================
Install       4 Package(s)

Total download size: 167 M
Installed size: 840 M
Downloading Packages:
(1/4): mysql-community-client-5.7.13-1.el6.x86_64.rpm                                                                                             |  22 MB     00:02
(2/4): mysql-community-common-5.7.13-1.el6.x86_64.rpm                                                                                             | 327 kB     00:00
(3/4): mysql-community-libs-5.7.13-1.el6.x86_64.rpm                                                                                               | 2.1 MB     00:00
(4/4): mysql-community-server-5.7.13-1.el6.x86_64.rpm                                                                                             | 143 MB     00:14
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                    9.9 MB/s | 167 MB     00:16
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : mysql-community-common-5.7.13-1.el6.x86_64                                                                                                            1/4
  Installing : mysql-community-libs-5.7.13-1.el6.x86_64                                                                                                              2/4
  Installing : mysql-community-client-5.7.13-1.el6.x86_64                                                                                                            3/4
  Installing : mysql-community-server-5.7.13-1.el6.x86_64                                                                                                            4/4
  Verifying  : mysql-community-client-5.7.13-1.el6.x86_64                                                                                                            1/4
  Verifying  : mysql-community-common-5.7.13-1.el6.x86_64                                                                                                            2/4
  Verifying  : mysql-community-libs-5.7.13-1.el6.x86_64                                                                                                              3/4
  Verifying  : mysql-community-server-5.7.13-1.el6.x86_64                                                                                                            4/4

Installed:
  mysql-community-server.x86_64 0:5.7.13-1.el6

Dependency Installed:
  mysql-community-client.x86_64 0:5.7.13-1.el6            mysql-community-common.x86_64 0:5.7.13-1.el6            mysql-community-libs.x86_64 0:5.7.13-1.el6

Complete!
```

## step4. インストールできたことを確認する

```
# mysqld --version
mysqld  Ver 5.7.13 for Linux on x86_64 (MySQL Community Server (GPL))
```

最新版のインストールに成功しました！
お疲れ様です。
こんにちわ！色々噂のMySQL5.7！！ｗ