Rocky Linux MariaDBをインストールする

Rocky Linux MariaDBをインストールする

Rocky LinuxにMariaDBをインストールするまでの手順を記述してます。

環境

  • OS Rocky Linux release 8.4 (Green Obsidian)

MariaDBインストール

appstreamにあるバージョンが「10.3」と新しいものなため、こちらからインストールします。

$ dnf list maria*

mariadb.x86_64                                                        3:10.3.28-1.module+el8.4.0+427+adf35707                                      @appstream
mariadb-backup.x86_64                                                 3:10.3.28-1.module+el8.4.0+427+adf35707                                      @appstream
mariadb-common.x86_64                                                 3:10.3.28-1.module+el8.4.0+427+adf35707                                      @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.28-1.module+el8.4.0+427+adf35707                                      @appstream
mariadb-errmsg.x86_64                                                 3:10.3.28-1.module+el8.4.0+427+adf35707                                      @appstream
mariadb-gssapi-server.x86_64                                          3:10.3.28-1.module+el8.4.0+427+adf35707                                      @appstream
mariadb-server.x86_64                                                 3:10.3.28-1.module+el8.4.0+427+adf35707                                      @appstream
mariadb-server-utils.x86_64                                           3:10.3.28-1.module+el8.4.0+427+adf35707                                      @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-odbc.x86_64                                         3.0.7-1.el8                                                                  appstream 
mariadb-embedded.x86_64                                               3:10.3.28-1.module+el8.4.0+427+adf35707                                      appstream 
mariadb-embedded-devel.x86_64                                         3:10.3.28-1.module+el8.4.0+427+adf35707                                      appstream 
mariadb-java-client.noarch                                            2.2.5-3.el8                                                                  appstream 
mariadb-oqgraph-engine.x86_64                                         3:10.3.28-1.module+el8.4.0+427+adf35707                                      appstream 
mariadb-server-galera.x86_64                                          3:10.3.28-1.module+el8.4.0+427+adf35707                                      appstream 
mariadb-test.x86_64                                                   3:10.3.28-1.module+el8.4.0+427+adf35707                                      appstream

インストールします。

$ sudo dnf install -y mariadb-server mariadb mariadb-devel

起動します。

$ sudo systemctl start mariadb

起動と自動起動を設定する場合は、以下を実行します。

$ sudo systemctl enable --now mariadb

初期化

初期化をしておきます。

$ 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キーを押します
Enter current password for root (enter for none): 
OK, successfully used password, moving on...

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

# rootのパスワードを設定するかです。設定するので y
Set root password? [Y/n] 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.

# 匿名ユーザーはいらないので y
Remove anonymous users? [Y/n] 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.

# rootでのリモート接続はさせないので y
Disallow root login remotely? [Y/n] y
 ... 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.

# テストDBは不要なので y
Remove test database and access to it? [Y/n] y
 - 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.

## 設定を反映させるので y
Reload privilege tables now? [Y/n] 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!

パスワードを設定したので、以下でログインしてみます。

$ mysql -u root -p

Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 19
Server version: 10.3.28-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)]> exit
Bye

さきほど作成したパスワードでログインできれば成功です。「exit」で抜けることが可能です。