MariaDBのインストール初期設定

Rocky Linuxをインストールした手習いで新規DBサーバーにMariaDB10.10をインストール、初期設定をしたのでメモ。

概要

はじめに

MySQL互換のデータベースソフトウェア MariaDBをRocky Linux 8新規VMにインストール、初期設定しました。

旧バージョンの削除

インストールするにあたって最初に、「dnf list」コマンドで旧バージョンのmariadb* が含まれているか調べて残っていればあらかじめ削除します。

# dnf list installed | grep 'mariadb'

# dnf remove mariadb*

.

リポジトリの取得・保存

MariaDB-server MariaDB-devel MariaDB-client をインストールするためMariaDB.org サイトからRHEL8のMariaDBリポジトリを取得します。

https://mariadb.org/download/?t=repo-config

.

vi /etc/yum.repos.d/MariaDB.repo を新規作成してリポジトリをコピー保存します。

# vi /etc/yum.repos.d/MariaDB.repo

.

MariaDBのインストール

続いてMariaDB-server MariaDB-client を「 dnf 」コマンドでインストールします。

# dnf install MariaDB-server MariaDB-client MariaDB-devel

.

MariaDBの起動

問題がなければMariaDBが起動します。ついでに自動起動します。

# systemctl start mariadb
# systemctl enable mariadb

.

MariaDB初期設定

初期設定は 「 mariadb-secure-installation 」コマンドで行います。

# mariadb-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 haven't set the root password yet, 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 or using the unix_socket ensures that nobody can log into the MariaDB root user without the proper authorisation. You already have your root account protected, so you can safely answer 'n'. Switch to unix_socket authentication [Y/n] n ... skipping. 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 ... 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 ... 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 - 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 ... 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!

server.cnf から文字セットをutf8mb4 に変更する

日本語圏の場合の最低限の文字セットの変更を server.cnf から行います。

# cp -p /etc/my.cnf.d/server.cnf /etc/my.cnf.d/mariadb-server.cnf.org

# vi /etc/my.cnf.d/server.cnf
# This group is only read by MariaDB servers, not by MySQL. # If you use the same .cnf file for MySQL and MariaDB, # you can put MariaDB-only options here [mariadb]
↓↓↓↓(ここから追記)↓↓↓↓ character-set-server = utf8mb4 [client-mariadb] default-character-set = utf8mb4

.

MariaDBを再起動して文字セットを確認する

問題がなければMariaDB再起動して「 mysql -u root -p 」コマンドで先ほど設定したパスワードからログイン、文字セットを確認します。

#  systemctl restart mariadb

.

MariaDBにログイン

# mysql -u root -p

MariaDB [(none)]> show variables like "chara%";

.

文字セットを確認

Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 10.10.3-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)]> 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     | utf8mb3                    |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.001 sec)

MariaDB [(none)]> \q
Bye

.

\q 」でログアウトして作業終了です。お疲れ様でした。

\q

.

character_set_system のutf8mb3 は utf8 のエイリアスとのことです。

途中、pidファイルがないとかエラーが出て再起動しても「もう無理!」という場合は最悪、アンインストールしてデータディレクトリ /var/lib/mysql を削除、最初から再インストールする方がスッキリします。

# rm -rf /var/lib/mysql

.

おわりに

データベースは構造やコマンドが奥深くMySQLとの互換性など注意すべきこともありますが習うより慣れろでやりたいことができているので開発者の方々に感謝です。最後までお読み下さりありがとうございました。

同じカテゴリーの記事

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です