Fedora WorkstationにMariaDBをインストール

Fedora WorkstationにMariaDBをインストール

Fedora Workstationにmysqlの互換DB「MariaDB」のインストール手順を記述してます。

fedoraバージョン

fedora30

MariaDBインストール

## インストール
sudo dnf -y install mariadb-server

## バージョン確認
mysql --version
mysql  Ver 15.1 Distrib 10.3.17-MariaDB, for Linux (x86_64) using readline 5.1

## 起動
sudo systemctl start mariadb

## 自動起動
sudo systemctl enable mariadb

## 設定ファイル編集
sudo vi /etc/my.cnf.d/mariadb-server.cnf

[mysqld]
追加
character-set-server=utf8mb4

## 再起動
sudo systemctl restart mariadb

初期設定

sudo mysql_secure_installation 

# 初期はROOTパスワードが無いのでEnter
Enter current password for root (enter for none): # Enterキー押下

# rootパスワードを設定しますか
Set root password? [Y/n] # Enterキー押下

# 新しいrootパスワードを設定
New password: # 新しいパスワードの入力

# 新しいパスワードの確認
Re-enter new password: # 新しいパスワードを再入力

# 匿名ユーザのログインを削除しますか
Remove anonymous users? [Y/n] # Enterキー押下

# rootでのリモートログインを禁止します
Disallow root login remotely? [Y/n] # Enterキー押下

# testデータベースを削除しますか
Remove test database and access to it? [Y/n]  # Enterキー押下

# 権限管理テーブルをリロードしますか
Reload privilege tables now? [Y/n] # Enterキー押下

Rootでログインしてみる

## ログイン
mysql -u root -p

## パスワードが聞かれるので先ほど設定したパスワードを入力
Enter password:

## ログイン成功
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 17
Server version: 10.3.17-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)]> 

firewallの設定

外部から接続する場合は必要

## portの恒久的許可
firewall-cmd --zone=public --add-port=3306/tcp --permanent

## サービスの許可
sudo firewall-cmd --add-service=mysql --permanent

## 再起動
sudo firewall-cmd --reload

接続テスト

## ユーザー作成
MariaDB [(none)]> CREATE USER 'dbtestuser'@'192.168.101.%' IDENTIFIED BY 'password';
Query OK, 0 rows affected (0.000 sec)

## 権限設定
MariaDB [(none)]> GRANT ALL ON *.* TO 'dbtestuser'@'192.168.101.%';
Query OK, 0 rows affected (0.000 sec)

## 接続テスト
mysql -u dbtestuser -h 192.168.101.XXX -p
Enter password: password

Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 12
Server version: 10.3.17-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.

接続できたので完了