そういうのがいいブログ

SIerで働く30代サラリーマンSEがインフラエンジニアに憧れてLinux・クラウド・AWSの勉強をするブログ

AlmaLinux 8にMySQL互換のデータベース MariaDB 10をインストールする手順

※[PR]当ブログの記事の中にはプロモーションが含まれています。

・AlmaLinux 8に、MariaDB 10をインストールする方法を知りたい。
・具体的な手順を教えてほしい。

こういった疑問に答えます。

本記事の内容

  1. AlmaLinux 8へのMariaDB10.3 のインストール手順
  2. MariaDBの起動方法、自動起動の設定手順
  3. MariaDBのインストール後の基本設定手順
  4. MariDBのテストDB作成手順

サトナカ (@souiunogaii)

この記事を書いている私は、某SIerに勤務しながら、
WEB系エンジニア・インフラエンジニアに憧れて、プログラミングおよびインフラ技術の勉強をしています。

こういった私が、解説していきます。

私が実機で試したコマンドや画像を載せて書いています。
記事の信頼性担保に繋がると思います。

AlmaLinux 8にMySQL互換のデータベース MariaDB 10をインストールする手順

手順① インストールする前のパッケージ確認

dnf list maria*
[root@SV-DENEB ~]# dnf list maria*
メタデータの期限切れの最終確認: 0:48:13 前の 20230901174627秒 に実施しました。
インストール済みパッケージ
mariadb-connector-c.x86_64               3.1.11-2.el8_3                                   @appstream
mariadb-connector-c-config.noarch        3.1.11-2.el8_3                                   @appstream
利用可能なパッケージ
mariadb.x86_64                           3:10.3.35-1.module_el8.6.0+3265+230ed96b         appstream
mariadb-backup.x86_64                    3:10.3.35-1.module_el8.6.0+3265+230ed96b         appstream
mariadb-common.x86_64                    3:10.3.35-1.module_el8.6.0+3265+230ed96b         appstream
mariadb-connector-c.i686                 3.1.11-2.el8_3                                   appstream
mariadb-connector-c-devel.i686           3.1.11-2.el8_3                                   appstream
mariadb-connector-c-devel.x86_64         3.1.11-2.el8_3                                   appstream
mariadb-connector-odbc.x86_64            3.1.12-1.el8                                     appstream
mariadb-devel.x86_64                     3:10.3.35-1.module_el8.6.0+3265+230ed96b         appstream
mariadb-embedded.x86_64                  3:10.3.35-1.module_el8.6.0+3265+230ed96b         appstream
mariadb-embedded-devel.x86_64            3:10.3.35-1.module_el8.6.0+3265+230ed96b         appstream
mariadb-errmsg.x86_64                    3:10.3.35-1.module_el8.6.0+3265+230ed96b         appstream
mariadb-gssapi-server.x86_64             3:10.3.35-1.module_el8.6.0+3265+230ed96b         appstream
mariadb-java-client.noarch               2.7.1-2.el8                                      appstream
mariadb-oqgraph-engine.x86_64            3:10.3.35-1.module_el8.6.0+3265+230ed96b         appstream
mariadb-server.x86_64                    3:10.3.35-1.module_el8.6.0+3265+230ed96b         appstream
mariadb-server-galera.x86_64             3:10.3.35-1.module_el8.6.0+3265+230ed96b         appstream
mariadb-server-utils.x86_64              3:10.3.35-1.module_el8.6.0+3265+230ed96b         appstream
mariadb-test.x86_64                      3:10.3.35-1.module_el8.6.0+3265+230ed96b         appstream

今回は3つのパッケージをインストールします。

  1. mariadb-server
  2. mariadb
  3. mariadb-devel
[root@SV-DENEB ~]# dnf info mariadb-server mariadb mariadb-devel
メタデータの期限切れの最終確認: 0:49:05 前の 20230901174627秒 に実施しました。
利用可能なパッケージ
名前         : mariadb
エポック     : 3
バージョン   : 10.3.35
リリース     : 1.module_el8.6.0+3265+230ed96b
Arch         : x86_64
サイズ       : 6.0 M
ソース       : mariadb-10.3.35-1.module_el8.6.0+3265+230ed96b.src.rpm
リポジトリー : appstream
概要         : A very fast and robust SQL database server
URL          : http://mariadb.org
ライセンス   : GPLv2 with exceptions and LGPLv2 and BSD
説明         : MariaDB is a community developed branch of MySQL - a multi-user, multi-threaded
             : SQL database server. It is a client/server implementation consisting of
             : a server daemon (mysqld) and many different client programs and libraries.
             : The base package contains the standard MariaDB/MySQL client programs and
             : generic MySQL files.

名前         : mariadb-devel
エポック     : 3
バージョン   : 10.3.35
リリース     : 1.module_el8.6.0+3265+230ed96b
Arch         : x86_64
サイズ       : 1.1 M
ソース       : mariadb-10.3.35-1.module_el8.6.0+3265+230ed96b.src.rpm
リポジトリー : appstream
概要         : Files for development of MariaDB/MySQL applications
URL          : http://mariadb.org
ライセンス   : GPLv2 with exceptions and LGPLv2 and BSD
説明         : MariaDB is a multi-user, multi-threaded SQL database server.
             : MariaDB is a community developed branch of MySQL.
             : This package contains everything needed for developing MariaDB/MySQL server
             : applications. For developing client applications, use mariadb-connector-c
             : package.

名前         : mariadb-server
エポック     : 3
バージョン   : 10.3.35
リリース     : 1.module_el8.6.0+3265+230ed96b
Arch         : x86_64
サイズ       : 16 M
ソース       : mariadb-10.3.35-1.module_el8.6.0+3265+230ed96b.src.rpm
リポジトリー : appstream
概要         : The MariaDB server and related files
URL          : http://mariadb.org
ライセンス   : GPLv2 with exceptions and LGPLv2 and BSD
説明         : MariaDB is a multi-user, multi-threaded SQL database server. It is a
             : client/server implementation consisting of a server daemon (mysqld)
             : and many different client programs and libraries. This package contains
             : the MariaDB server and some accompanying files and directories.
             : MariaDB is a community developed branch of MySQL.

手順② インストール実行

dnf install -y mariadb-server mariadb mariadb-devel
[root@SV-DENEB ~]# dnf install -y mariadb-server mariadb mariadb-devel
メタデータの期限切れの最終確認: 0:49:37 前の 20230901174627秒 に実施しました。
依存関係が解決しました。
====================================================================================================
 パッケージ                  Arch     バージョン                                  Repo        サイズ
====================================================================================================
インストール:
 mariadb                     x86_64   3:10.3.35-1.module_el8.6.0+3265+230ed96b    appstream   6.0 M
 mariadb-devel               x86_64   3:10.3.35-1.module_el8.6.0+3265+230ed96b    appstream   1.1 M
 mariadb-server              x86_64   3:10.3.35-1.module_el8.6.0+3265+230ed96b    appstream    16 M
依存関係のインストール:
 keyutils-libs-devel         x86_64   1.5.10-9.el8                                baseos       47 k
 krb5-devel                  x86_64   1.18.2-25.el8_8                             baseos      561 k
 libcom_err-devel            x86_64   1.45.6-5.el8                                baseos       38 k
 libkadm5                    x86_64   1.18.2-25.el8_8                             baseos      187 k
 libselinux-devel            x86_64   2.9-8.el8                                   baseos      199 k
 libsepol-devel              x86_64   2.9-3.el8                                   baseos       86 k
 libverto-devel              x86_64   0.3.2-2.el8                                 baseos       17 k
 mariadb-common              x86_64   3:10.3.35-1.module_el8.6.0+3265+230ed96b    appstream    63 k
 mariadb-connector-c-devel   x86_64   3.1.11-2.el8_3                              appstream    68 k
 mariadb-errmsg              x86_64   3:10.3.35-1.module_el8.6.0+3265+230ed96b    appstream   234 k
 openssl-devel               x86_64   1:1.1.1k-9.el8_7                            baseos      2.3 M
 pcre2-devel                 x86_64   10.32-3.el8_6                               baseos      604 k
 pcre2-utf16                 x86_64   10.32-3.el8_6                               baseos      228 k
 pcre2-utf32                 x86_64   10.32-3.el8_6                               baseos      219 k
 perl-DBD-MySQL              x86_64   4.046-3.module_el8.6.0+2827+49d66dc3        appstream   155 k
 perl-DBI                    x86_64   1.641-4.module_el8.6.0+2823+173faa7e        appstream   739 k
 perl-Math-BigInt            noarch   1:1.9998.11-7.el8                           baseos      195 k
 perl-Math-Complex           noarch   1.59-422.el8.0.1                            baseos      108 k
 zlib-devel                  x86_64   1.2.11-21.el8_7                             baseos       57 k
弱い依存関係のインストール:
 mariadb-backup              x86_64   3:10.3.35-1.module_el8.6.0+3265+230ed96b    appstream   6.1 M
 mariadb-gssapi-server       x86_64   3:10.3.35-1.module_el8.6.0+3265+230ed96b    appstream    51 k
 mariadb-server-utils        x86_64   3:10.3.35-1.module_el8.6.0+3265+230ed96b    appstream   1.1 M
モジュールストリームの有効化中:
 mariadb                              10.3
 perl-DBD-MySQL                       4.046
 perl-DBI                             1.641

トランザクションの概要
====================================================================================================
インストール  25 パッケージ

ダウンロードサイズの合計: 37 M
インストール後のサイズ: 169 M
パッケージのダウンロード:
(1/25): libcom_err-devel-1.45.6-5.el8.x86_64.rpm                    670 kB/s |  38 kB     00:00
(2/25): keyutils-libs-devel-1.5.10-9.el8.x86_64.rpm                 681 kB/s |  47 kB     00:00
(3/25): krb5-devel-1.18.2-25.el8_8.x86_64.rpm                       3.4 MB/s | 561 kB     00:00
(4/25): libselinux-devel-2.9-8.el8.x86_64.rpm                       1.9 MB/s | 199 kB     00:00
(5/25): libsepol-devel-2.9-3.el8.x86_64.rpm                         3.2 MB/s |  86 kB     00:00
(6/25): libkadm5-1.18.2-25.el8_8.x86_64.rpm                         1.3 MB/s | 187 kB     00:00
(7/25): libverto-devel-0.3.2-2.el8.x86_64.rpm                       518 kB/s |  17 kB     00:00
(8/25): pcre2-utf16-10.32-3.el8_6.x86_64.rpm                        1.8 MB/s | 228 kB     00:00
(9/25): pcre2-utf32-10.32-3.el8_6.x86_64.rpm                        1.9 MB/s | 219 kB     00:00
(10/25): pcre2-devel-10.32-3.el8_6.x86_64.rpm                       2.1 MB/s | 604 kB     00:00
(11/25): perl-Math-BigInt-1.9998.11-7.el8.noarch.rpm                2.1 MB/s | 195 kB     00:00
(12/25): perl-Math-Complex-1.59-422.el8.0.1.noarch.rpm              1.6 MB/s | 108 kB     00:00
(13/25): zlib-devel-1.2.11-21.el8_7.x86_64.rpm                      1.9 MB/s |  57 kB     00:00
(14/25): openssl-devel-1.1.1k-9.el8_7.x86_64.rpm                    5.6 MB/s | 2.3 MB     00:00
(15/25): mariadb-common-10.3.35-1.module_el8.6.0+3265+230ed96b.x86_ 895 kB/s |  63 kB     00:00
(16/25): mariadb-connector-c-devel-3.1.11-2.el8_3.x86_64.rpm        879 kB/s |  68 kB     00:00
(17/25): mariadb-devel-10.3.35-1.module_el8.6.0+3265+230ed96b.x86_6 2.5 MB/s | 1.1 MB     00:00
(18/25): mariadb-errmsg-10.3.35-1.module_el8.6.0+3265+230ed96b.x86_ 2.3 MB/s | 234 kB     00:00
(19/25): mariadb-gssapi-server-10.3.35-1.module_el8.6.0+3265+230ed9 1.1 MB/s |  51 kB     00:00
(20/25): mariadb-10.3.35-1.module_el8.6.0+3265+230ed96b.x86_64.rpm  3.6 MB/s | 6.0 MB     00:01
(21/25): mariadb-server-utils-10.3.35-1.module_el8.6.0+3265+230ed96 2.9 MB/s | 1.1 MB     00:00
(22/25): perl-DBD-MySQL-4.046-3.module_el8.6.0+2827+49d66dc3.x86_64 1.7 MB/s | 155 kB     00:00
(23/25): mariadb-backup-10.3.35-1.module_el8.6.0+3265+230ed96b.x86_ 2.8 MB/s | 6.1 MB     00:02
(24/25): perl-DBI-1.641-4.module_el8.6.0+2823+173faa7e.x86_64.rpm   3.0 MB/s | 739 kB     00:00
(25/25): mariadb-server-10.3.35-1.module_el8.6.0+3265+230ed96b.x86_ 5.8 MB/s |  16 MB     00:02
----------------------------------------------------------------------------------------------------
合計                                                                7.0 MB/s |  37 MB     00:05
トランザクションの確認を実行中
トランザクションの確認に成功しました。
トランザクションのテストを実行中
トランザクションのテストに成功しました。
トランザクションを実行中
  準備             :                                                                            1/1
  インストール中   : mariadb-common-3:10.3.35-1.module_el8.6.0+3265+230ed96b.x86_64            1/25
  インストール中   : zlib-devel-1.2.11-21.el8_7.x86_64                                         2/25
  インストール中   : mariadb-errmsg-3:10.3.35-1.module_el8.6.0+3265+230ed96b.x86_64            3/25
  インストール中   : perl-Math-Complex-1.59-422.el8.0.1.noarch                                 4/25
  インストール中   : perl-Math-BigInt-1:1.9998.11-7.el8.noarch                                 5/25
  インストール中   : perl-DBI-1.641-4.module_el8.6.0+2823+173faa7e.x86_64                      6/25
  インストール中   : perl-DBD-MySQL-4.046-3.module_el8.6.0+2827+49d66dc3.x86_64                7/25
  インストール中   : mariadb-3:10.3.35-1.module_el8.6.0+3265+230ed96b.x86_64                   8/25
  インストール中   : mariadb-backup-3:10.3.35-1.module_el8.6.0+3265+230ed96b.x86_64            9/25
  インストール中   : mariadb-gssapi-server-3:10.3.35-1.module_el8.6.0+3265+230ed96b.x86_64    10/25
  scriptletの実行中: mariadb-server-3:10.3.35-1.module_el8.6.0+3265+230ed96b.x86_64           11/25
  インストール中   : mariadb-server-3:10.3.35-1.module_el8.6.0+3265+230ed96b.x86_64           11/25
  scriptletの実行中: mariadb-server-3:10.3.35-1.module_el8.6.0+3265+230ed96b.x86_64           11/25
  インストール中   : mariadb-server-utils-3:10.3.35-1.module_el8.6.0+3265+230ed96b.x86_64     12/25
  インストール中   : pcre2-utf32-10.32-3.el8_6.x86_64                                         13/25
  インストール中   : pcre2-utf16-10.32-3.el8_6.x86_64                                         14/25
  インストール中   : pcre2-devel-10.32-3.el8_6.x86_64                                         15/25
  インストール中   : libverto-devel-0.3.2-2.el8.x86_64                                        16/25
  インストール中   : libsepol-devel-2.9-3.el8.x86_64                                          17/25
  インストール中   : libselinux-devel-2.9-8.el8.x86_64                                        18/25
  インストール中   : libkadm5-1.18.2-25.el8_8.x86_64                                          19/25
  インストール中   : libcom_err-devel-1.45.6-5.el8.x86_64                                     20/25
  インストール中   : keyutils-libs-devel-1.5.10-9.el8.x86_64                                  21/25
  インストール中   : krb5-devel-1.18.2-25.el8_8.x86_64                                        22/25
  インストール中   : openssl-devel-1:1.1.1k-9.el8_7.x86_64                                    23/25
  インストール中   : mariadb-connector-c-devel-3.1.11-2.el8_3.x86_64                          24/25
  インストール中   : mariadb-devel-3:10.3.35-1.module_el8.6.0+3265+230ed96b.x86_64            25/25
  scriptletの実行中: mariadb-devel-3:10.3.35-1.module_el8.6.0+3265+230ed96b.x86_64            25/25
  検証             : keyutils-libs-devel-1.5.10-9.el8.x86_64                                   1/25
  検証             : krb5-devel-1.18.2-25.el8_8.x86_64                                         2/25
  検証             : libcom_err-devel-1.45.6-5.el8.x86_64                                      3/25
  検証             : libkadm5-1.18.2-25.el8_8.x86_64                                           4/25
  検証             : libselinux-devel-2.9-8.el8.x86_64                                         5/25
  検証             : libsepol-devel-2.9-3.el8.x86_64                                           6/25
  検証             : libverto-devel-0.3.2-2.el8.x86_64                                         7/25
  検証             : openssl-devel-1:1.1.1k-9.el8_7.x86_64                                     8/25
  検証             : pcre2-devel-10.32-3.el8_6.x86_64                                          9/25
  検証             : pcre2-utf16-10.32-3.el8_6.x86_64                                         10/25
  検証             : pcre2-utf32-10.32-3.el8_6.x86_64                                         11/25
  検証             : perl-Math-BigInt-1:1.9998.11-7.el8.noarch                                12/25
  検証             : perl-Math-Complex-1.59-422.el8.0.1.noarch                                13/25
  検証             : zlib-devel-1.2.11-21.el8_7.x86_64                                        14/25
  検証             : mariadb-3:10.3.35-1.module_el8.6.0+3265+230ed96b.x86_64                  15/25
  検証             : mariadb-backup-3:10.3.35-1.module_el8.6.0+3265+230ed96b.x86_64           16/25
  検証             : mariadb-common-3:10.3.35-1.module_el8.6.0+3265+230ed96b.x86_64           17/25
  検証             : mariadb-connector-c-devel-3.1.11-2.el8_3.x86_64                          18/25
  検証             : mariadb-devel-3:10.3.35-1.module_el8.6.0+3265+230ed96b.x86_64            19/25
  検証             : mariadb-errmsg-3:10.3.35-1.module_el8.6.0+3265+230ed96b.x86_64           20/25
  検証             : mariadb-gssapi-server-3:10.3.35-1.module_el8.6.0+3265+230ed96b.x86_64    21/25
  検証             : mariadb-server-3:10.3.35-1.module_el8.6.0+3265+230ed96b.x86_64           22/25
  検証             : mariadb-server-utils-3:10.3.35-1.module_el8.6.0+3265+230ed96b.x86_64     23/25
  検証             : perl-DBD-MySQL-4.046-3.module_el8.6.0+2827+49d66dc3.x86_64               24/25
  検証             : perl-DBI-1.641-4.module_el8.6.0+2823+173faa7e.x86_64                     25/25

インストール済み:
  keyutils-libs-devel-1.5.10-9.el8.x86_64
  krb5-devel-1.18.2-25.el8_8.x86_64
  libcom_err-devel-1.45.6-5.el8.x86_64
  libkadm5-1.18.2-25.el8_8.x86_64
  libselinux-devel-2.9-8.el8.x86_64
  libsepol-devel-2.9-3.el8.x86_64
  libverto-devel-0.3.2-2.el8.x86_64
  mariadb-3:10.3.35-1.module_el8.6.0+3265+230ed96b.x86_64
  mariadb-backup-3:10.3.35-1.module_el8.6.0+3265+230ed96b.x86_64
  mariadb-common-3:10.3.35-1.module_el8.6.0+3265+230ed96b.x86_64
  mariadb-connector-c-devel-3.1.11-2.el8_3.x86_64
  mariadb-devel-3:10.3.35-1.module_el8.6.0+3265+230ed96b.x86_64
  mariadb-errmsg-3:10.3.35-1.module_el8.6.0+3265+230ed96b.x86_64
  mariadb-gssapi-server-3:10.3.35-1.module_el8.6.0+3265+230ed96b.x86_64
  mariadb-server-3:10.3.35-1.module_el8.6.0+3265+230ed96b.x86_64
  mariadb-server-utils-3:10.3.35-1.module_el8.6.0+3265+230ed96b.x86_64
  openssl-devel-1:1.1.1k-9.el8_7.x86_64
  pcre2-devel-10.32-3.el8_6.x86_64
  pcre2-utf16-10.32-3.el8_6.x86_64
  pcre2-utf32-10.32-3.el8_6.x86_64
  perl-DBD-MySQL-4.046-3.module_el8.6.0+2827+49d66dc3.x86_64
  perl-DBI-1.641-4.module_el8.6.0+2823+173faa7e.x86_64
  perl-Math-BigInt-1:1.9998.11-7.el8.noarch
  perl-Math-Complex-1.59-422.el8.0.1.noarch
  zlib-devel-1.2.11-21.el8_7.x86_64

完了しました!

インストール後のパッケージ確認

dnf list installed | grep mariadb
[root@SV-DENEB ~]# dnf list installed | grep mariadb
mariadb.x86_64                       3:10.3.35-1.module_el8.6.0+3265+230ed96b @appstream
mariadb-backup.x86_64                3:10.3.35-1.module_el8.6.0+3265+230ed96b @appstream
mariadb-common.x86_64                3:10.3.35-1.module_el8.6.0+3265+230ed96b @appstream
mariadb-connector-c.x86_64           3.1.11-2.el8_3                           @appstream
mariadb-connector-c-config.noarch    3.1.11-2.el8_3                           @appstream
mariadb-connector-c-devel.x86_64     3.1.11-2.el8_3                           @appstream
mariadb-devel.x86_64                 3:10.3.35-1.module_el8.6.0+3265+230ed96b @appstream
mariadb-errmsg.x86_64                3:10.3.35-1.module_el8.6.0+3265+230ed96b @appstream
mariadb-gssapi-server.x86_64         3:10.3.35-1.module_el8.6.0+3265+230ed96b @appstream
mariadb-server.x86_64                3:10.3.35-1.module_el8.6.0+3265+230ed96b @appstream
mariadb-server-utils.x86_64          3:10.3.35-1.module_el8.6.0+3265+230ed96b @appstream

手順③ MariaDBの起動

systemctl start mariadb
systemctl status mariadb
[root@SV-DENEB ~]# systemctl start mariadb
[root@SV-DENEB ~]# systemctl status mariadb
● mariadb.service - MariaDB 10.3 database server
   Loaded: loaded (/usr/lib/systemd/system/mariadb.service; disabled; vendor preset: disabled)
   Active: active (running) since Fri 2023-09-01 18:37:09 JST; 9s ago
     Docs: man:mysqld(8)
           https://mariadb.com/kb/en/library/systemd/
  Process: 5697 ExecStartPost=/usr/libexec/mysql-check-upgrade (code=exited, status=0/SUCCESS)
  Process: 5562 ExecStartPre=/usr/libexec/mysql-prepare-db-dir mariadb.service (code=exited, status>
  Process: 5537 ExecStartPre=/usr/libexec/mysql-check-socket (code=exited, status=0/SUCCESS)
 Main PID: 5665 (mysqld)
   Status: "Taking your SQL requests now..."
    Tasks: 30 (limit: 24822)
   Memory: 83.1M
   CGroup: /system.slice/mariadb.service
           mq5665 /usr/libexec/mysqld --basedir=/usr

 901 18:37:09 SV-DENEB mysql-prepare-db-dir[5603]: which will also give you the option of removi>
 901 18:37:09 SV-DENEB mysql-prepare-db-dir[5603]: databases and anonymous user created by defau>
 901 18:37:09 SV-DENEB mysql-prepare-db-dir[5603]: strongly recommended for production servers.
 901 18:37:09 SV-DENEB mysql-prepare-db-dir[5603]: See the MariaDB Knowledgebase at http://maria>
 901 18:37:09 SV-DENEB mysql-prepare-db-dir[5603]: Please report any problems at http://mariadb.>
 901 18:37:09 SV-DENEB mysql-prepare-db-dir[5603]: The latest information about MariaDB is avail>
 901 18:37:09 SV-DENEB mysql-prepare-db-dir[5603]: Consider joining MariaDB's strong and vibrant>
 9月 01 18:37:09 SV-DENEB mysql-prepare-db-dir[5603]: https://mariadb.org/get-involved/
 9月 01 18:37:09 SV-DENEB mysqld[5665]: 2023-09-01 18:37:09 0 [Note] /usr/libexec/mysqld (mysqld 10>
 9月 01 18:37:09 SV-DENEB systemd[1]: Started MariaDB 10.3 database server.

プロセス確認

ps -aux | grep mysqld
[root@SV-DENEB ~]# ps -aux | grep mysqld
mysql       5665  0.1  2.2 1758496 89220 ?       Ssl  18:37   0:00 /usr/libexec/mysqld --basedir=/usr

自動起動するように設定

systemctl enable mariadb
systemctl is-enabled mariadb
[root@SV-DENEB ~]# systemctl enable mariadb
Created symlink /etc/systemd/system/mysql.service → /usr/lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/mysqld.service → /usr/lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/multi-user.target.wants/mariadb.service → /usr/lib/systemd/system/mariadb.service.

[root@SV-DENEB ~]# systemctl is-enabled mariadb
enabled

手順④ セキュアインストレーションの実行

mysql_secure_installation
[root@SV-DENEB ~]# mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):    ←←←'★★何も入力せずにEnterキー
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] y   ←←←★★y
New password:   ←←←★★自分で決めたパスワード
Re-enter new password:   ←←←★★自分で決めたパスワード
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y  ←←←★★y 匿名ユーザー削除
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y  ←←←★★y リモート管理者rootログインの拒否
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y  ←←←★★y テストDBの削除
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y  ←←←★★y 権限テーブルに即時反映
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

手順⑤ MariaDBインストール後に最初にやる初期設定

mariadb-server.cnf の変更

cp -p /etc/my.cnf.d/mariadb-server.cnf /etc/my.cnf.d/mariadb-server.cnf.original_bk
vi /etc/my.cnf.d/mariadb-server.cnf
     46 # This group is only read by MariaDB servers, not by MySQL.
     47 # If you use the same .cnf file for MySQL and MariaDB,
     48 # you can put MariaDB-only options here
     49 [mariadb]
     50 character-set-server = utf8mb4  ←←←★★変更
     51 [client-mariadb]  ←←←★★追記
     52 default-character-set = utf8mb4  ←←←★★追記

変更後のMariaDB再起動

systemctl restart mariadb
systemctl status mariadb
[root@SV-DENEB ~]# systemctl restart mariadb
[root@SV-DENEB ~]# systemctl status mariadb
● mariadb.service - MariaDB 10.3 database server
   Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
   Active: active (running) since Fri 2023-09-01 18:47:27 JST; 9s ago
     Docs: man:mysqld(8)
           https://mariadb.com/kb/en/library/systemd/
  Process: 5889 ExecStartPost=/usr/libexec/mysql-check-upgrade (code=exited, status=0/SUCCESS)
  Process: 5820 ExecStartPre=/usr/libexec/mysql-prepare-db-dir mariadb.service (code=exited, status>
  Process: 5793 ExecStartPre=/usr/libexec/mysql-check-socket (code=exited, status=0/SUCCESS)
 Main PID: 5857 (mysqld)
   Status: "Taking your SQL requests now..."
    Tasks: 30 (limit: 24822)
   Memory: 74.0M
   CGroup: /system.slice/mariadb.service
           mq5857 /usr/libexec/mysqld --basedir=/usr

 901 18:47:27 SV-DENEB systemd[1]: mariadb.service: Succeeded.
 901 18:47:27 SV-DENEB systemd[1]: Stopped MariaDB 10.3 database server.
 901 18:47:27 SV-DENEB systemd[1]: Starting MariaDB 10.3 database server...
 901 18:47:27 SV-DENEB mysql-prepare-db-dir[5820]: Database MariaDB is probably initialized in />
 901 18:47:27 SV-DENEB mysql-prepare-db-dir[5820]: If this is not the case, make sure the /var/l>
 9月 01 18:47:27 SV-DENEB mysqld[5857]: 2023-09-01 18:47:27 0 [Note] /usr/libexec/mysqld (mysqld 10>
 9月 01 18:47:27 SV-DENEB systemd[1]: Started MariaDB 10.3 database server.

手順⑥ 動作確認

ログイン

mysql -uroot -p●●●自分で決めたパスワード
[root@SV-DENEB ~]# mysql -uroot -p●●●自分で決めたパスワード
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 8
Server version: 10.3.35-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>

テストDBを作成

create database test_db;
MariaDB [(none)]> create database test_db;
Query OK, 1 row affected (0.000 sec)

DBの表示

show databases;
MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test_db            |
+--------------------+
4 rows in set (0.000 sec)

DBの変更

use test_db;
MariaDB [(none)]> use test_db;
Database changed

文字コード確認

MariaDB [test_db]> show variables like "chara%"
    -> ;
+--------------------------+------------------------------+
| Variable_name            | Value                        |
+--------------------------+------------------------------+
| character_set_client     | utf8mb4                      |
| character_set_connection | utf8mb4                      |
| character_set_database   | utf8mb4                      |
| character_set_filesystem | binary                       |
| character_set_results    | utf8mb4                      |
| character_set_server     | utf8mb4                      |
| character_set_system     | utf8                         |
| character_sets_dir       | /usr/share/mariadb/charsets/ |
+--------------------------+------------------------------+
8 rows in set (0.001 sec)

テスト用DBの削除

drop database test_db;
show databases;
MariaDB [test_db]> drop database test_db;
Query OK, 0 rows affected (0.001 sec)

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.000 sec)

終了

quit
MariaDB [(none)]> quit
Bye