LoginSignup
1
2

More than 3 years have passed since last update.

MariaDB Community Server 10.4.11 - Installing on Windows 10

Last updated at Posted at 2019-12-26

概要

Windows10に開発・検証用にMariaDB Community Server 10.4.11をインストールし、初歩的な設定を行うまでの作業メモです。
インストーラー版は使わずZIP Archive版で手動インストールします。
※MySQL 5.7のインストール方法とほぼ同じですが一部異なる点があった為、改めて記事として作成しました。

環境

  • Windows 10 Professional 1909
  • MariaDB Community Server 10.4.11 (zip archive)

参考

MariaDB Community Server インストール

アーカイブファイルのダウンロード

ダウンロードページよりアーカイブファイルをダウンロードします。
今回ダウンロードしたアーカイブファイルは2019年12月時点で最新バージョンのmariadb-10.4.11-winx64.zipです。

アーカイブファイルの展開

アーカイブファイルを適当な場所へ展開します。今回はD:\dev\mariadb-10.4.11-winx64にしました。
次に下記ディレクトリを作成します。

作成
D:\dev\mariadb-10.4.11-winx64\logs
D:\dev\mariadb-10.4.11-winx64\tmp
D:\dev\mariadb-10.4.11-winx64\uploads

データファイルを格納するdataディレクトリは既に存在するので改めて作成はしませんが、dataディレクトリの下にtestディレクトリがあるので、これは削除します。

削除
D:\dev\mariadb-10.4.11-winx64\data\test

データディレクトリの初期化

mysql_install_dbを使ってデータディレクトリを初期化します。
※ここはMySQLとは異なる点で、MySQLでは--initializeオプションを使用しますが、MariaDBにはそのオプションはありません。
※MariaDB 10.3まではZipアーカイブにデータディレクトリも含まれているため初期化作業は不要です。

> mysql_install_db.exe --datadir=D:\dev\mariadb-10.4.11-winx64\data --password=<rootのパスワード>
Running bootstrap
2019-12-26  0:51:07 0 [Note] D:\dev\mariadb-10.4.11-winx64\bin\mysqld.exe (mysqld 10.4.11-MariaDB) starting as process 11116 ...
Removing default user
Setting root password
Creating my.ini file
Creation of the database was successful

初期化が終わるとdataディレクトリ下に以下のディレクトリが作成されています。
またmy.iniも作成されていますが、これは一つ上のディレクトリへ移動させておきます。

mysql
performance_schema
test

my.iniの編集

上記で作成されたmy.iniを下記のように修正します。

[mysqld]
basedir = D:\\dev\\mariadb-10.4.11-winx64
datadir = D:\\dev\mariadb-10.4.11-winx64\\data
tmpdir = D:\\dev\mariadb-10.4.11-winx64\\tmp
secure_file_priv = D:\\dev\mariadb-10.4.11-winx64\\uploads

max_connections = 30

#default-time-zone = Asia/Tokyo

innodb_status_output = TRUE
innodb_status_output_locks = TRUE

character_set_server = utf8
collation_server = utf8_general_ci

general_log = TRUE
general_log_file = D:\\dev\\mariadb-10.4.11-winx64\\logs\\general_query_all.log
log_error = D:\\dev\\mariadb-10.4.11-winx64\\logs\\mysqld_error.log
log_queries_not_using_indexes = TRUE
long_query_time = 3
slow_query_log = TRUE
slow_query_log_file = D:\\dev\\mariadb-10.4.11-winx64\\logs\\slow_query.log

log_slow_verbosity = query_plan,explain

[mysql]
default_character_set = cp932
show_warnings

plugin-dir = D:\\dev\\mariadb-10.4.11-winx64\\lib\\plugin

prompt = "\u@\h [\d] > "

Performance Schema

MariaDBではパフォーマンス上の理由からデフォルトではOFFになっています。有効にしたい場合はperformance_schemaをTRUEに設定します。

performance_schema = TRUE

sql_mode

デフォルトが異なります。

MariaDBのデフォルト
sql_mode = STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
MySQL5.7のデフォルト
sql_mode = ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

mariadbの起動と停止

起動

mysqld.exe --defaults-file=D:\dev\mariadb-10.4.11-winx64\my.ini --console

rootユーザでログイン

passwordはデータディレクトリを初期化するときに指定したパスワードになります。

mysql.exe --defaults-file=D:\dev\mariadb-10.4.11-winx64\my.ini -u root -p

停止

mysqladmin.exe -u root -p shutdown

インストール後の環境確認、設定

オプションの確認と設定値の出力

mariadbが起動している状態で実行、結果が長いのでtextファイルに出力しています。

mysqld.exe --defaults-file=D:\dev\mariadb-10.4.11-winx64\my.ini --help --verbose > option_dump.txt

タイムゾーンデータのインポート

※この作業は必須ではありません。必要に応じて実行します。

Time zone description tablesより、タイムゾーンのデータをダウンロードします。
MariaDB 10.4はMySQL 5.7と互換性があるので、5.7+のtimezone_2019c_posix_sql.zipをダウンロードします。

The other set is for 5.7+. Each file contains SQL statements to fill the tables:

  • timezone_2019c_posix_sql.zip - POSIX standard
  • timezone_2019c_leaps_sql.zip - Non POSIX with leap seconds

zipファイルからtimezone_posix.sqlを取出し、下記のコマンドでインポートします。

mysql.exe --defaults-file=D:\dev\mariadb-10.4.11-winx64\my.ini -u root -p -D mysql < timezone_posix.sql

MariaDBを一旦停止し、my.iniの下記の行を有効にします。

default-time-zone = Asia/Tokyo

JDBC

JDBC URL

jdbc:mariadb://<host>[:<portnumber>]/[database][?<key1>=<value1>[&<key2>=<value2>]]
example
jdbc:mariadb://localhost:3306/db

Maven

<!-- https://mvnrepository.com/artifact/org.mariadb.jdbc/mariadb-java-client -->
<dependency>
    <groupId>org.mariadb.jdbc</groupId>
    <artifactId>mariadb-java-client</artifactId>
    <version>2.5.2</version>
    <scope>runtime</scope>
</dependency>

Gradle

// https://mvnrepository.com/artifact/org.mariadb.jdbc/mariadb-java-client
runtimeOnly group: 'org.mariadb.jdbc', name: 'mariadb-java-client', version: '2.5.2'

補足

開発用のDB、アカウントの作成

CREATE DATABASE IF NOT EXISTS sample_db
  CHARACTER SET = utf8mb4
  COLLATE = utf8mb4_general_ci
;
CREATE USER IF NOT EXISTS 'test_user'@'localhost'
  IDENTIFIED BY 'test_user'
  PASSWORD EXPIRE NEVER
;

データベースsample_dbにALL(すべての権限、GRANT OPTIONを除く)を付与します。

GRANT ALL ON sample_db.* TO 'test_user'@'localhost';

FILEはグルーバル権限なのでON *.*とします。

GRANT FILE ON *.* TO 'test_user'@'localhost';

SHOW CHARACTER SET

SHOW CHARACTER SET

SHOW COLLATION

SHOW COLLATION
example
show collation where charset like 'utf8';

Installing on Windows 10 Series

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2