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

# はじめに

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

### mysql起動/停止

```shell-session
# systemctl start rh-mariadb103-mariadb
# systemctl status rh-mariadb103-mariadb
● rh-mariadb103-mariadb.service - MariaDB 10.3 database server
   Loaded: loaded (/usr/lib/systemd/system/rh-mariadb103-mariadb.service; disabled; vendor preset: disabled)
   Active: active (running) since Mon 2019-10-21 15:35:41 UTC; 3s ago
     Docs: man:mysqld(8)
           https://mariadb.com/kb/en/library/systemd/
  Process: 416 ExecStartPost=/usr/bin/scl enable $RH_MARIADB103_SCLS_ENABLED -- /opt/rh/rh-mariadb103/root/usr/libexec/mysql-check-upgrade (code=exited, status=0/SUCCESS)
  Process: 271 ExecStartPre=/usr/bin/scl enable $RH_MARIADB103_SCLS_ENABLED -- /opt/rh/rh-mariadb103/root/usr/libexec/mysql-prepare-db-dir %n (code=exited, status=0/SUCCESS)
  Process: 243 ExecStartPre=/usr/bin/scl enable $RH_MARIADB103_SCLS_ENABLED -- /opt/rh/rh-mariadb103/root/usr/libexec/mysql-check-socket (code=exited, status=0/SUCCESS)
  Process: 237 ExecStartPre=/usr/bin/scl enable $RH_MARIADB103_SCLS_ENABLED -- /usr/bin/scl_enabled rh-mariadb103 (code=exited, status=0/SUCCESS)
 Main PID: 382 (mysqld)
   Status: "Taking your SQL requests now..."
   CGroup: /docker/011f6ffa80c75a17570114bb45dddf2080a80f01fb1daa49dfbd58eadc02edf9/system.slice/rh-mariadb103-mariadb.service
           mq382 /opt/rh/rh-mariadb103/root/usr/libexec/mysqld --basedir=/opt/rh/rh-mariadb103/root/usr
           ? 382 /opt/rh/rh-mariadb103/root/usr/libexec/mysqld --basedir=/opt/rh/rh-mariadb103/root/usr

Oct 21 15:35:34 011f6ffa80c7 systemd[1]: Starting MariaDB 10.3 database server...
Oct 21 15:35:34 011f6ffa80c7 scl[271]: Initializing MariaDB database
Oct 21 15:35:41 011f6ffa80c7 scl[271]: PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER !
Oct 21 15:35:41 011f6ffa80c7 scl[271]: To do so, start the server, then issue the following commands:
Oct 21 15:35:41 011f6ffa80c7 mysqld-scl-helper[382]: 2019-10-21 15:35:41 0 [Note] /opt/rh/rh-mariadb103/......
Oct 21 15:35:41 011f6ffa80c7 systemd[1]: Started MariaDB 10.3 database server.
Hint: Some lines were ellipsized, use -l to show in full.
```

```shell-session
# systemctl stop rh-mariadb103-mariadb
# systemctl status rh-mariadb103-mariadb
● rh-mariadb103-mariadb.service - MariaDB 10.3 database server
   Loaded: loaded (/usr/lib/systemd/system/rh-mariadb103-mariadb.service; disabled; vendor preset: disabled)
   Active: inactive (dead)
     Docs: man:mysqld(8)
           https://mariadb.com/kb/en/library/systemd/

Oct 21 15:35:34 011f6ffa80c7 systemd[1]: Starting MariaDB 10.3 database server...
Oct 21 15:35:34 011f6ffa80c7 scl[271]: Initializing MariaDB database
Oct 21 15:35:41 011f6ffa80c7 scl[271]: PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER !
Oct 21 15:35:41 011f6ffa80c7 scl[271]: To do so, start the server, then issue the following commands:
Oct 21 15:35:41 011f6ffa80c7 mysqld-scl-helper[382]: 2019-10-21 15:35:41 0 [Note] /opt/rh/rh-mariadb103/......
Oct 21 15:35:41 011f6ffa80c7 systemd[1]: Started MariaDB 10.3 database server.
Oct 21 15:36:17 011f6ffa80c7 systemd[1]: Stopping MariaDB 10.3 database server...
Oct 21 15:36:20 011f6ffa80c7 systemd[1]: Stopped MariaDB 10.3 database server.
Hint: Some lines were ellipsized, use -l to show in full.
```

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

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

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

### 各種確認

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