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

# はじめに

Software Collection(SCL)を利用してCentOS7にMariaDB10.5をインストール
親記事：[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)より、2024-06がEOLだと思われる。
それ以降に報告された脆弱性や不具合への対応は実施されない可能性がある。

## LOG

### レポジトリ登録

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

### インストール

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

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

### mysql起動/停止

```shell-session
# systemctl start rh-mariadb105-mariadb
# systemctl status rh-mariadb105-mariadb
● rh-mariadb105-mariadb.service - MariaDB 10.5 database server
   Loaded: loaded (/usr/lib/systemd/system/rh-mariadb105-mariadb.service; disabled; vendor preset: disabled)
   Active: active (running) since Mon 2021-07-12 09:59:46 UTC; 3s ago
     Docs: man:mysqld(8)
           https://mariadb.com/kb/en/library/systemd/
  Process: 365 ExecStartPost=/usr/bin/scl enable $RH_MARIADB105_SCLS_ENABLED -- /opt/rh/rh-mariadb105/root/usr/libexec/mysql-check-upgrade (code=exited, status=0/SUCCESS)
  Process: 262 ExecStartPre=/usr/bin/scl enable $RH_MARIADB105_SCLS_ENABLED -- /opt/rh/rh-mariadb105/root/usr/libexec/mysql-prepare-db-dir %n (code=exited, status=0/SUCCESS)
  Process: 234 ExecStartPre=/usr/bin/scl enable $RH_MARIADB105_SCLS_ENABLED -- /opt/rh/rh-mariadb105/root/usr/libexec/mysql-check-socket (code=exited, status=0/SUCCESS)
  Process: 228 ExecStartPre=/usr/bin/scl enable $RH_MARIADB105_SCLS_ENABLED -- /usr/bin/scl_enabled rh-mariadb105 (code=exited, status=0/SUCCESS)
 Main PID: 350 (mysqld)
   Status: "Taking your SQL requests now..."
   CGroup: /docker/b24aceb83e8cfaa30e47f6dce1531963bb58c79c89f644331f451efee07e2fcc/system.slice/rh-mariadb105-mariadb.service
           mq350 /opt/rh/rh-mariadb105/root/usr/libexec/mysqld --basedir=/opt/rh/rh-mariadb105/root/usr
           ? 350 /opt/rh/rh-mariadb105/root/usr/libexec/mysqld --basedir=/opt/rh/rh-mariadb105/root/usr

Jul 12 09:59:42 b24aceb83e8c systemd[1]: Starting MariaDB 10.5 database server...
Jul 12 09:59:42 b24aceb83e8c scl[262]: Initializing MariaDB database
Jul 12 09:59:46 b24aceb83e8c scl[262]: Two all-privilege accounts were created.
Jul 12 09:59:46 b24aceb83e8c mysqld-scl-helper[350]: 2021-07-12  9:59:46 0 [Note] /opt/rh/rh-mariadb105/......
Jul 12 09:59:46 b24aceb83e8c systemd[1]: Started MariaDB 10.5 database server.
Hint: Some lines were ellipsized, use -l to show in full.
```

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

Jul 12 09:59:42 b24aceb83e8c systemd[1]: Starting MariaDB 10.5 database server...
Jul 12 09:59:42 b24aceb83e8c scl[262]: Initializing MariaDB database
Jul 12 09:59:46 b24aceb83e8c scl[262]: Two all-privilege accounts were created.
Jul 12 09:59:46 b24aceb83e8c mysqld-scl-helper[350]: 2021-07-12  9:59:46 0 [Note] /opt/rh/rh-mariadb105/......
Jul 12 09:59:46 b24aceb83e8c systemd[1]: Started MariaDB 10.5 database server.
Jul 12 10:00:25 b24aceb83e8c systemd[1]: Stopping MariaDB 10.5 database server...
Jul 12 10:00:25 b24aceb83e8c systemd[1]: Stopped MariaDB 10.5 database server.
Hint: Some lines were ellipsized, use -l to show in full.
```

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

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

```shell-session
# systemctl disable rh-mariadb105-mariadb
Removed symlink /etc/systemd/system/multi-user.target.wants/rh-mariadb105-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-mariadb105-mariadb.service          disabled
rh-mariadb105-mariadb@.service         disabled
```

### 各種確認

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