概要
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 Server Documentation] (https://mariadb.com/kb/en/documentation/)
- [Installing MariaDB Windows ZIP Packages] (https://mariadb.com/kb/en/installing-mariadb-windows-zip-packages/)
- [Configuring MariaDB with Option Files] (https://mariadb.com/kb/en/configuring-mariadb-with-option-files/)
MariaDB Community Server インストール
アーカイブファイルのダウンロード
[ダウンロードページ] (https://downloads.mariadb.org/mariadb/+releases/)よりアーカイブファイルをダウンロードします。
今回ダウンロードしたアーカイブファイルは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
データディレクトリの初期化
- 参考: [Installing System Tables (mysql_install_db)] (https://mariadb.com/kb/en/installing-system-tables-mysql_install_db/)
[mysql_install_db] (https://dev.mysql.com/doc/refman/5.7/en/mysql-install-db.html)を使ってデータディレクトリを初期化します。
※ここは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
デフォルトが異なります。
sql_mode = STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
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] (https://dev.mysql.com/downloads/timezones.html)より、タイムゾーンのデータをダウンロードします。
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
- 参考: [About MariaDB Connector/J] (https://mariadb.com/kb/en/about-mariadb-connector-j/)
JDBC URL
jdbc:mariadb://<host>[:<portnumber>]/[database][?<key1>=<value1>[&<key2>=<value2>]]
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] (https://mariadb.com/kb/en/show-character-set/)
SHOW CHARACTER SET
[SHOW COLLATION] (https://mariadb.com/kb/en/show-collation/)
SHOW COLLATION
show collation where charset like 'utf8';
Installing on Windows 10 Series
- [PostgreSQL 10.4.1 - Installing on Windows 10] (https://qiita.com/rubytomato@github/items/cfcca181ced2058ed7d6)
- [MongoDB Community Edition 3.6.2 - Installing on Windows 10] (https://qiita.com/rubytomato@github/items/6746f6ddbf6eade46b35)
- [MySQL Community Server 5.7.19 - Installing on Windows 10] (https://qiita.com/rubytomato@github/items/15ec40069f2eec57b25f)
- [PostgreSQL 9.6.1 - Installing on Windows 10] (https://qiita.com/rubytomato@github/items/be540f2c1bd3605cacae)