Windows Server 2019 に MariaDB をインストール

MariaDBの設定

公式サイトから mariadb-10.2.30-win32.msi をダウンロードしてインストール

MariaDB 10.2.30 Stable - MariaDB

パスワード: password

☑ Enable access from remote machines for 'root' user

☑ Use UTF8 as default serever's character set

f:id:akifumi-ichiki:20201110173202p:plain

f:id:akifumi-ichiki:20201110173307p:plain

f:id:akifumi-ichiki:20201110173322p:plain

環境変数の設定

f:id:akifumi-ichiki:20201110173354p:plain

コマンドプロンプトを起動して

mysql --version

データベースの作成

mysql -uroot -p
password
CREATE DATABASE DatabaseName;
GRANT ALL PRIVILEGES ON DatabaseName.* TO UserName@'192.168.1.%' IDENTIFIED BY 'password' WITH GRANT OPTION;
FLUSH PRIVILEGES;
C:\Users\Administrator>mysql -uroot -p
Enter password: **********
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 10
Server version: 10.2.30-MariaDB mariadb.org binary distribution

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)]> CREATE DATABASE DatabaseName;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> GRANT ALL PRIVILEGES ON DatabaseName.* TO UserName@'192.168.1.%' IDENTIFIED BY 'password' WITH GRANT OPTION;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]>

WITH GRANT OPTIONを付け加えると、他のユーザの権限を書き換えることが可能になるのでrootとは別に管理者ユーザーを作成する時に使える

GRANT ALL PRIVILEGES ON *.* TO 'ユーザー名'@'ホスト名' IDENTIFIED BY 'パスワード' WITH GRANT OPTION;
FLUSH PRIVILEGES;

GRANT構文を実行した後は「FLUSH PRIVILEGES;」を実行して権限を反映させる

HeidiSQLの設定

セッションの作成

MariaDB付属のHeidiSQLを起動してセッションマネージャ左下のNewをクリック

Network type: MariaDB or MySQL (TCP/IP)

Hostname/IP: 127.0.0.1

User: UserName

Password: password

Port: 3306

f:id:akifumi-ichiki:20201110174207p:plain

開発用のパソコンからデータベースをエクスポート

f:id:akifumi-ichiki:20201110174607p:plain

データベース: ☑ドロップ!! ☑作成

テーブル: ☑ドロップ!! ☑作成

データ:削除して挿入(既存データを削除)

最大INSERTサイズ: 1,024

出力:単一の.sqlファイル

ファイル名:DatabaseName.sql

サーバーのHeidiSQLにインポート

Run SQL file でエクセルファイルを開くとインポートされる

f:id:akifumi-ichiki:20201110174830p:plain

WindowsファイアーウォールでのMySQLのポート開放

  1. コントロールパネルを開き、[System and Security]カテゴリの[Check firewall status]リンクをクリックします。
  2. Windowsファイアウォールのウィンドウが開きます。左側のメニューの[Advanced settings]リンクをクリックします。
  3. 左側のビューの[Inbound Rules]ノードを選択します。右側の[Actions]ビューの[New Rules]リンクをクリックします。
  4. [New Inbound Rule Wizard]ダイアログが表示されます。規則の種類として[Port]をチェックします。[Next]ボタンを押し次に進みます。
  5. プロトコルは[TCP]を選択します。ポートは[Specific local ports]を選択し、MySQLのポート3306(デフォルトの場合)を指定します。
  6. 条件が一致した場合の操作は[Allow the connection]にします。
  7. プロファイルはデフォルトのまま(Domain、Private、Publicに適用)とします。
  8. 規則の種類の名前と説明文を入力し、[Finish]ボタンを押します。以上でWindowsファイアウォールにポート3306を許可する設定ができました。

規則の種類

名前: MySQL

説明文: MySQL Database Server

MariaDBに開発機から接続

MariaDB付属のHeidiSQLを起動してセッションマネージャ左下のNewをクリック

Network type: MariaDB or MySQL (TCP/IP)

Hostname/IP: 192.168.1.27

User: UserName

Password: password

Port: 3306