DEV Community

nabbisen
nabbisen

Posted on • Originally published at obsd.solutions

MariaDB 10.9 on OpenBSD 7.3: インストール

はじめに

MariaDB は広く使われているリレーショナル (関係) データベース管理システム (RDBMS) の一つです。MySQL から、オリジナルの開発者たちの一部によってフォークされました。
オープンソースであり、GNU GPL 2ライセンスされています。長い歴史と管理維持のための知見の蓄積があり、コミュニティでも企業でも使えます。

堅牢でクリーンなオペレーティング・システムである OpenBSD へのインストールは容易です。パッケージ管理 (英語) システム ("ports") を維持してくれているすばらしいプロジェクトとコミュニティのおかげです。

本記事ではその流れを説明します。

環境

  • OS: OpenBSD 7.3
  • データベース: MariaDB 10.9.4

基本の手順

これだけです !!

# pkg_add mariadb-server
# rcctl enable mysqld

# mysql_install_db

# rcctl start mysqld

# mysql_secure_installation
# # いくつかの質問に答える必要があります
Enter fullscreen mode Exit fullscreen mode

詳細は以下でお示しします。

チュートリアル

パッケージをインストール

$ doas pkg_add mariadb-server
Enter fullscreen mode Exit fullscreen mode

結果は以下の通りでした:

quirks-6.122 signed on 2023-09-01T21:25:11Z
mariadb-server-10.9.4v1:(...): ok
mariadb-server-10.9.4v1: ok
The following new rcscripts were installed: /etc/rc.d/mysqld
See rcctl(8) for details.
New and changed readme(s):
    /usr/local/share/doc/pkg-readmes/mariadb-server
Enter fullscreen mode Exit fullscreen mode

上記のように、pkg-readme が /usr/local/share/doc/pkg-readmes/mariadb-server として配置されます。

デーモンを有効化

$ doas rcctl enable mysqld
Enter fullscreen mode Exit fullscreen mode

mysql_install_db を実行

初期データベースを作成します:

$ doas mysql_install_db
Enter fullscreen mode Exit fullscreen mode

結果は以下の通りでした:

WARNING: The host '(...)' could not be looked up with /usr/local/bin/resolveip.
This probably means that your libc libraries are not 100 % compatible
with this binary MariaDB version. The MariaDB daemon, mysqld, should work
normally with the exception that host name resolving will not work.
This means that you should use IP addresses instead of hostnames
when specifying MariaDB privileges !
Installing MariaDB/MySQL system tables in '/var/mysql' ...
OK


Two all-privilege accounts were created.
One is root@localhost, it has no password, but you need to
be system 'root' user to connect. Use, for example, sudo mysql
The second is _mysql@localhost, it has no password either, but
you need to be the system '_mysql' user to connect.
After connecting you can set the password, if you would need to be
able to connect as any of these users with a password and without sudo

See the MariaDB Knowledgebase at https://mariadb.com/kb

You can start the MariaDB daemon with:
/etc/rc.d/mysqld start

Please report any problems at https://mariadb.org/jira

The latest information about MariaDB is available at https://mariadb.org/.

Consider joining MariaDB's strong and vibrant community:
https://mariadb.org/get-involved/
Enter fullscreen mode Exit fullscreen mode

デーモンを起動

$ doas rcctl start mysqld
mysqld(ok)
Enter fullscreen mode Exit fullscreen mode

mysql_secure_installation を実行

$ doas mysql_secure_installation
Enter fullscreen mode Exit fullscreen mode

始まり (最初の質問までに出力される内容)

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

質問に回答する

Q1: 現在の root パスワード

初回起動の場合、未設定のはずです。Enter だけを押しましょう。

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): 
OK, successfully used password, moving on...
Enter fullscreen mode Exit fullscreen mode

これ以降の質問には、私が回答した内容を記します。実際は、あなたの環境次第です。

Q2: root パスワードの代わりに unix_socket 認証を使用するか
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.
Enter fullscreen mode Exit fullscreen mode
Q3: root パスワードの設定
You already have your root account protected, so you can safely answer 'n'.

Change the root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Enter fullscreen mode Exit fullscreen mode
Q4: 匿名ユーザーを削除するか
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!
Enter fullscreen mode Exit fullscreen mode
Q5: root ユーザーはリモート環境からはログインできないようにするか
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!
Enter fullscreen mode Exit fullscreen mode
Q6: テスト用データベースを削除するか
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!
Enter fullscreen mode Exit fullscreen mode
Q7: 権限テーブルを今リロードするか
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
 ... Success!
Enter fullscreen mode Exit fullscreen mode

終わり (残りの出力内容)

Cleaning up...

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

Thanks for using MariaDB!
Enter fullscreen mode Exit fullscreen mode

おわりに

次のようにすることで、デーモンが正常に動いていることを確認できます:

$ doas rcctl check mysqld
mysqld(ok)
Enter fullscreen mode Exit fullscreen mode

それでは、クライアントからサーバーに接続してみましょう。root すなわちスーパーユーザーを使います:

$ mysql -u root -p
Enter fullscreen mode Exit fullscreen mode

パスワードを入力すると、以下のように迎え入れられるでしょう:

Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 11
Server version: 10.9.4-MariaDB OpenBSD port: mariadb-server-10.9.4v1

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)]>
Enter fullscreen mode Exit fullscreen mode

コマンドのサンプルです:

-- データベースを作成
CREATE DATABASE <database> \
    CHARACTER SET utf8mb4 \
    COLLATE utf8mb4_unicode_ci;

-- そのデータベース用のユーザーを作成
GRANT ALL PRIVILEGES \
    ON <database>.* \
    TO <dbuser>@'localhost' \
    IDENTIFIED BY '<dbpass>';

-- 権限をリロード
FLUSH PRIVILEGES;
Enter fullscreen mode Exit fullscreen mode

🎵 🐬 Happy storing digitally 🐬 🎵

Top comments (0)