CentOS 7にMySQL 5.7をインストール（SCL）

# はじめに

Software Collection(SCL)を利用してCentOS7にMySQL5.7をインストール
親記事：[MySQL, MariaDBの各種インストール方法とEOLまとめ \- Qiita](https://qiita.com/witchcraze/items/72291ee035437ec83273)
参考：[Quick Start — Software Collections](https://www.softwarecollections.org/en/docs/)

## サポート

本手法で導入した場合、[Red Hat Software Collections Product Life Cycle - Red Hat Customer Portal](https://access.redhat.com/support/policy/updates/rhscl)より、2019-11がEOLだと思われる。
それ以降に報告された脆弱性や不具合への対応は実施されない可能性がある。

## LOG

### レポジトリ登録

```shell-session
# yum install -y centos-release-scl
```

### インストール

```shell-session
# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)

# yum install -y rh-mysql57
# scl enable rh-mysql57 bash
... 略
```

### mysql起動/停止

```shell-session
# systemctl start rh-mysql57-mysqld
# systemctl status rh-mysql57-mysqld
● rh-mysql57-mysqld.service - MySQL 5.7 database server
   Loaded: loaded (/usr/lib/systemd/system/rh-mysql57-mysqld.service; disabled; vendor preset: disabled)
   Active: active (running) since Mon 2019-10-21 14:41:23 UTC; 2s ago
  Process: 374 ExecStartPost=/usr/bin/scl enable $RH_MYSQL57_SCLS_ENABLED -- /opt/rh/rh-mysql57/root/usr/libexec/mysql-check-upgrade (code=exited, status=0/SUCCESS)
  Process: 341 ExecStart=/opt/rh/rh-mysql57/root/usr/libexec/mysqld-scl-helper enable $RH_MYSQL57_SCLS_ENABLED -- /opt/rh/rh-mysql57/root/usr/libexec/mysqld --daemonize --basedir=/opt/rh/rh-mysql57/root/usr --pid-file=/var/run/rh-mysql57-mysqld/mysqld.pid (code=exited, status=0/SUCCESS)
  Process: 272 ExecStartPre=/usr/bin/scl enable $RH_MYSQL57_SCLS_ENABLED -- /opt/rh/rh-mysql57/root/usr/libexec/mysql-prepare-db-dir %n (code=exited, status=0/SUCCESS)
  Process: 244 ExecStartPre=/usr/bin/scl enable $RH_MYSQL57_SCLS_ENABLED -- /opt/rh/rh-mysql57/root/usr/libexec/mysql-check-socket (code=exited, status=0/SUCCESS)
  Process: 238 ExecStartPre=/usr/bin/scl enable $RH_MYSQL57_SCLS_ENABLED -- /usr/bin/scl_enabled rh-mysql57 (code=exited, status=0/SUCCESS)
 Main PID: 346 (mysqld)
   CGroup: /docker/9b923d2bfd11f4560910084714df4eaaf5cb9d71beed1f4e226ed570f9127ecd/system.slice/rh-mysql57-mysqld.service
           mq346 /opt/rh/rh-mysql57/root/usr/libexec/mysqld --daemonize --basedir=/opt/rh/rh-mysql57/root/u...
           ? 346 /opt/rh/rh-mysql57/root/usr/libexec/mysqld --daemonize --basedir=/opt/rh/rh-mysql57/root/u...

Oct 21 14:41:13 9b923d2bfd11 systemd[1]: Starting MySQL 5.7 database server...
Oct 21 14:41:13 9b923d2bfd11 scl[272]: Initializing MySQL database
Oct 21 14:41:23 9b923d2bfd11 systemd[1]: Started MySQL 5.7 database server.
```

```shell-session
# systemctl stop rh-mysql57-mysqld
# systemctl status rh-mysql57-mysqld
● rh-mysql57-mysqld.service - MySQL 5.7 database server
   Loaded: loaded (/usr/lib/systemd/system/rh-mysql57-mysqld.service; disabled; vendor preset: disabled)
   Active: inactive (dead)

Oct 21 14:41:13 9b923d2bfd11 systemd[1]: Starting MySQL 5.7 database server...
Oct 21 14:41:13 9b923d2bfd11 scl[272]: Initializing MySQL database
Oct 21 14:41:23 9b923d2bfd11 systemd[1]: Started MySQL 5.7 database server.
Oct 21 14:41:47 9b923d2bfd11 systemd[1]: Stopping MySQL 5.7 database server...
Oct 21 14:41:49 9b923d2bfd11 systemd[1]: Stopped MySQL 5.7 database server.
```

### mysql自動起動設定/設定解除

```shell-session
# systemctl enable rh-mysql57-mysqld
Created symlink from /etc/systemd/system/multi-user.target.wants/rh-mysql57-mysqld.service to /usr/lib/systemd/system/rh-mysql57-mysqld.service.
# systemctl list-unit-files --type=service |grep mysql
rh-mysql57-mysqld.service              enabled
rh-mysql57-mysqld@.service             disabled
```

```shell-session
# systemctl disable rh-mysql57-mysqld
Removed symlink /etc/systemd/system/multi-user.target.wants/rh-mysql57-mysqld.service.
# systemctl list-unit-files --type=service |grep mysql
rh-mysql57-mysqld.service              disabled
rh-mysql57-mysqld@.service             disabled
```

### 各種確認

```shell-session
# systemctl start rh-mysql57-mysqld
# mysql -u root -e 'select version();'
+-----------+
| version() |
+-----------+
| 5.7.24    |
+-----------+
```