CentOS 7にMariaDB 10.2をインストール（SCL）

# はじめに

Software Collection(SCL)を利用してCentOS7にMariaDB10.2をインストール
親記事：[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)より、2020-10が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-mariadb102
# scl enable rh-mariadb102 bash
... 略
```

### mysql起動/停止

```shell-session
# systemctl start rh-mariadb102-mariadb
# systemctl status rh-mariadb102-mariadb
● rh-mariadb102-mariadb.service - MariaDB 10.2 database server
   Loaded: loaded (/usr/lib/systemd/system/rh-mariadb102-mariadb.service; disabled; vendor preset: disabled)
   Active: active (running) since Mon 2019-10-21 15:29:06 UTC; 2s ago
  Process: 438 ExecStartPost=/usr/bin/scl enable $RH_MARIADB102_SCLS_ENABLED -- /opt/rh/rh-mariadb102/root/usr/libexec/mysql-check-upgrade (code=exited, status=0/SUCCESS)
  Process: 293 ExecStartPre=/usr/bin/scl enable $RH_MARIADB102_SCLS_ENABLED -- /opt/rh/rh-mariadb102/root/usr/libexec/mysql-prepare-db-dir %n (code=exited, status=0/SUCCESS)
  Process: 265 ExecStartPre=/usr/bin/scl enable $RH_MARIADB102_SCLS_ENABLED -- /opt/rh/rh-mariadb102/root/usr/libexec/mysql-check-socket (code=exited, status=0/SUCCESS)
  Process: 259 ExecStartPre=/usr/bin/scl enable $RH_MARIADB102_SCLS_ENABLED -- /usr/bin/scl_enabled rh-mariadb102 (code=exited, status=0/SUCCESS)
 Main PID: 404 (mysqld)
   Status: "Taking your SQL requests now..."
   CGroup: /docker/e4434a415a7d71ee920882c06cb0640fe91c8c58d790552e25a50abc1cbb924f/system.slice/rh-mariadb102-mariadb.service
           mq404 /opt/rh/rh-mariadb102/root/usr/libexec/mysqld --basedir=/opt/rh/rh-mariadb102/root/usr
           ? 404 /opt/rh/rh-mariadb102/root/usr/libexec/mysqld --basedir=/opt/rh/rh-mariadb102/root/usr

Oct 21 15:29:01 e4434a415a7d systemd[1]: Starting MariaDB 10.2 database server...
Oct 21 15:29:03 e4434a415a7d scl[293]: Initializing MariaDB database
Oct 21 15:29:06 e4434a415a7d scl[293]: PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER !
Oct 21 15:29:06 e4434a415a7d scl[293]: To do so, start the server, then issue the following commands:
Oct 21 15:29:06 e4434a415a7d mysqld-scl-helper[404]: 2019-10-21 15:29:06 139751341181120 [Note] /opt/rh/......
Oct 21 15:29:06 e4434a415a7d systemd[1]: Started MariaDB 10.2 database server.
Hint: Some lines were ellipsized, use -l to show in full.
```

```shell-session
# systemctl stop rh-mariadb102-mariadb
# systemctl status rh-mariadb102-mariadb
● rh-mariadb102-mariadb.service - MariaDB 10.2 database server
   Loaded: loaded (/usr/lib/systemd/system/rh-mariadb102-mariadb.service; disabled; vendor preset: disabled)
   Active: inactive (dead)

Oct 21 15:29:01 e4434a415a7d systemd[1]: Starting MariaDB 10.2 database server...
Oct 21 15:29:03 e4434a415a7d scl[293]: Initializing MariaDB database
Oct 21 15:29:06 e4434a415a7d scl[293]: PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER !
Oct 21 15:29:06 e4434a415a7d scl[293]: To do so, start the server, then issue the following commands:
Oct 21 15:29:06 e4434a415a7d mysqld-scl-helper[404]: 2019-10-21 15:29:06 139751341181120 [Note] /opt/rh/......
Oct 21 15:29:06 e4434a415a7d systemd[1]: Started MariaDB 10.2 database server.
Oct 21 15:29:33 e4434a415a7d systemd[1]: Stopping MariaDB 10.2 database server...
Oct 21 15:29:35 e4434a415a7d systemd[1]: Stopped MariaDB 10.2 database server.
Hint: Some lines were ellipsized, use -l to show in full.
```

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

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

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

### 各種確認

```shell-session
# systemctl start rh-mariadb102-mariadb
# mysql -u root -e 'select version();'
+-----------------+
| version()       |
+-----------------+
| 10.2.22-MariaDB |
+-----------------+
```