概要
Windows 10に開発・検証用にMySQL Community Server 8.0.11 GAをインストールし、初歩的な設定を行うまでの作業メモです。
インストーラー版は使わずZIP Archive版で手動インストールします。
環境
- Windows 10 Professional
- MySQL Community Server 8.0.11 (zip archive)
参考
- [MySQL 8.0 Reference Manual - 2.3 Installing MySQL on Microsoft Windows] (https://dev.mysql.com/doc/refman/8.0/en/windows-installation.html)
- [MySQL 8.0 Reference Manual - 2.3.5 Installing MySQL on Microsoft Windows Using a noinstall ZIP Archive] (https://dev.mysql.com/doc/refman/8.0/en/windows-install-archive.html)
- [MySQL 8.0 Release Notes - Changes in MySQL 8.0.11 (2018-04-19, General Availability)] (https://dev.mysql.com/doc/relnotes/mysql/8.0/en/news-8-0-11.html)
インストール
Microsoft Visual C++ 2015 再頒布可能パッケージのインストール
MySQL 8.0 Server requires the Microsoft Visual C++ 2015 Redistributable Package to run on Windows platforms.
MySQL 8.0 Serverの実行には"Microsoft Visual C++ 2015 Redistributable Package"が必要ということなので、この記事では"Microsoft Visual C++ 2015 再頒布可能パッケージ Update 3"をダウンロードしインストールしました。
アーカイブファイルのダウンロード
ダウンロードページよりアーカイブファイルをダウンロードします。今回ダウンロードしたアーカイブファイルはmysql-8.0.11-winx64.zipです。
ダウンロードしたアーカイブファイルのMD5のハッシュ値をチェックします。
> certutil -hashfile mysql-8.0.11-winx64.zip MD5
MD5 ハッシュ (対象 mysql-8.0.11-winx64.zip):
0b4efe256a28cd391bf057d4c61ade09
CertUtil: -hashfile コマンドは正常に完了しました。
アーカイブファイルの展開
アーカイブファイルを適当な場所へ展開します。今回はD:\dev\mysql-8.0.11-winx64にしました。
次にdata、logs、tmpディレクトリを下記の場所に作成します。
D:\dev\mysql-8.0.11-winx64\data
D:\dev\mysql-8.0.11-winx64\logs
D:\dev\mysql-8.0.11-winx64\tmp
Option File(my.ini)の準備
以下の場所にmy.iniファイルを作成します。
D:\dev\mysql-8.0.11-winx64\my.ini
今回使用したmy.iniファイルは下記の通りです。
[mysqld]
basedir = D:\\dev\\mysql-8.0.11-winx64
datadir = D:\\dev\\mysql-8.0.11-winx64\\data
tmpdir = D:\\dev\\mysql-8.0.11-winx64\\tmp
## logging
general_log = 1
general_log_file = D:\\dev\\mysql-8.0.11-winx64\\logs\\general_query_all.log
log_error = D:\\dev\\mysql-8.0.11-winx64\\logs\\mysqld_error.log
log_queries_not_using_indexes = 1
log_slow_admin_statements = 1
log_syslog = 0
log_timestamps = SYSTEM
long_query_time = 3
slow_query_log = 1
slow_query_log_file = D:\\dev\\mysql-8.0.11-winx64\\logs\\slow_query.log
データディレクトリの初期化
D:\dev\mysql-8.0.11-winx64> bin\mysqld --defaults-file=D:\dev\mysql-8.0.11-winx64\my.ini --initialize
初期化に成功すればエラーログ(mysqld_error.log)にrootユーザーの一時パスワードが出力されているので控えます。
[System] [MY-013169] [Server] D:\dev\mysql-8.0.11-winx64\bin\mysqld.exe (mysqld 8.0.11) initializing of server in progress as process 8688
[Note] [MY-010454] [Server] A temporary password is generated for root@localhost: _8rufd+%vu:P
[System] [MY-013170] [Server] D:\dev\mysql-8.0.11-winx64\bin\mysqld.exe (mysqld 8.0.11) initializing of server has completed
mysql serverの起動と接続
起動
D:\dev\mysql-8.0.11-winx64> bin\mysqld --defaults-file=D:\dev\mysql-8.0.11-winx64\my.ini --console
rootユーザーでログイン
一時パスワードでログインします。
D:\dev\mysql-8.0.11-winx64> bin\mysql -u root -p
Enter password: <temporary password>
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.11
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
root@localhost [(none)] >
rootユーザーの一時パスワードを変更する
> ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password';
Query OK, 0 rows affected (0.13 sec)
インストールされているユーザーを確認
> SELECT user, host, password_expired, password_lifetime FROM mysql.user;
+------------------+-----------+------------------+-------------------+
| user | host | password_expired | password_lifetime |
+------------------+-----------+------------------+-------------------+
| mysql.infoschema | localhost | N | NULL |
| mysql.session | localhost | N | NULL |
| mysql.sys | localhost | N | NULL |
| root | localhost | N | NULL |
+------------------+-----------+------------------+-------------------+
4 rows in set (0.00 sec)
予約済みアカウント
- mysql.infoschema
- mysql.session
- mysql.sys
停止
D:\dev\mysql-8.0.11-winx64> bin\mysqladmin -u root -p shutdown
テスト
MySQL Serverを起動させている状態で実行します。
D:\dev\mysql-8.0.11-winx64> bin\mysqlshow --defaults-file=D:\dev\mysql-8.0.11-winx64\my.ini -u root -p mysql
Enter password: ********
Database: mysql
+---------------------------+
| Tables |
+---------------------------+
| columns_priv |
| component |
| db |
| default_roles |
| engine_cost |
| func |
| general_log |
| global_grants |
| gtid_executed |
| help_category |
| help_keyword |
| help_relation |
| help_topic |
| innodb_index_stats |
| innodb_table_stats |
| password_history |
| plugin |
| procs_priv |
| proxies_priv |
| role_edges |
| server_cost |
| servers |
| slave_master_info |
| slave_relay_log_info |
| slave_worker_info |
| slow_log |
| tables_priv |
| time_zone |
| time_zone_leap_second |
| time_zone_name |
| time_zone_transition |
| time_zone_transition_type |
| user |
+---------------------------+
D:\dev\mysql-8.0.11-winx64> bin\mysqladmin --defaults-file=D:\dev\mysql-8.0.11-winx64\my.ini -u root -p version status proc
Enter password: ********
Server version 8.0.11
Protocol version 10
Connection localhost via TCP/IP
TCP port 3306
Uptime: 15 min 15 sec
Threads: 2 Questions: 32 Slow queries: 0 Opens: 143 Flush tables: 2 Open tables: 119 Queries per second avg: 0.034
Uptime: 915 Threads: 2 Questions: 33 Slow queries: 0 Opens: 143 Flush tables: 2 Open tables: 119 Queries per second avg: 0.036
+----+-----------------+-----------------+----+---------+------+------------------------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+-----------------+-----------------+----+---------+------+------------------------+------------------+
| 4 | event_scheduler | localhost | | Daemon | 912 | Waiting on empty queue | |
| 23 | root | localhost:50374 | | Query | 0 | starting | show processlist |
+----+-----------------+-----------------+----+---------+------+------------------------+------------------+
タイムゾーンの設定
- [MySQL 5.6 リファレンスマニュアル / グローバリゼーション / MySQL Server でのタイムゾーンのサポート] (https://dev.mysql.com/doc/refman/5.6/ja/time-zone-support.html)
[Time zone description tables] (https://dev.mysql.com/downloads/timezones.html)より、タイムゾーン情報テーブルのデータをダウンロードします。
下記リンクのPOSIX standard
よりダウンロード。
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
ダウンロードしたアーカイブファイルからtimezone_posix.sql
というsqlファイルを展開し、下記コマンドで取り込みます。
> mysql -u root -p -Dmysql < .\timezone_posix.sql
MySQLサーバーを停止して、my.iniファイルのmysqld
セクションに下記の通りタイムゾーンを指定します。
[mysqld]
default-time-zone = 'Japan'
MySQLサーバーを起動し設定が反映されていることを確認します。
> show variables like '%time_zone%';
+------------------+-------+
| Variable_name | Value |
+------------------+-------+
| system_time_zone | JST |
| time_zone | Japan |
+------------------+-------+
2 rows in set (0.02 sec)
補足
開発用の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
;
権限
GRANT ALL ON sample_db.* TO 'test_user'@'localhost';
テーブル
USE sample_db;
Database changed
CREATE TABLE IF NOT EXISTS memo (
id BIGINT AUTO_INCREMENT,
title VARCHAR(255) NOT NULL,
description TEXT NOT NULL,
done BOOLEAN DEFAULT FALSE NOT NULL,
updated TIMESTAMP(3) DEFAULT CURRENT_TIMESTAMP(3) NOT NULL,
PRIMARY KEY (id)
) CHARACTER SET = utf8mb4, COLLATE utf8mb4_0900_ai_ci;
テストデータ
insert into memo (title, description, done) values ('memo 1', 'memo description 1', false);
insert into memo (title, description, done) values ('メモ 2', 'メモ 説明 2', false);
Warning (Code 1366): Incorrect String value...について
もしかしたら環境固有の現象かもしれませんが、show variables
を実行すると、Warning (Code 1366): Incorrect String value: ...というワーニングが出力されます。
> show variables like '%time_zone%';
+------------------+--------+
| Variable_name | Value |
+------------------+--------+
| system_time_zone | |
| time_zone | SYSTEM |
+------------------+--------+
2 rows in set, 1 warning (0.00 sec)
Warning (Code 1366): Incorrect string value: '\x93\x8C\x8B\x9E (...' for column 'VARIABLE_VALUE' at row 518
原因と解決方法をいろいろ探したのですがこれといった情報は見つからなかったので正しいかどうか不安ですが、下記のようにTZ環境変数を設定することでワーニングが出力されなくなります。
> show variables like '%time_zone%';
+------------------+--------+
| Variable_name | Value |
+------------------+--------+
| system_time_zone | JST |
| time_zone | SYSTEM |
+------------------+--------+
2 rows in set (0.00 sec)
Spring Bootアプリケーションから接続する場合
- [Chapter 6 Connector/J (JDBC) Reference] (https://dev.mysql.com/doc/connector-j/8.0/en/connector-j-reference.html)
Connector/J
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.11</version>
<scope>runtime</scope>
</dependency>
driver-class-name
com.mysql.cj.jdbc.Driver
Hibernate ORM 5.2
[Package org.hibernate.dialect] (https://docs.jboss.org/hibernate/orm/5.2/javadocs/org/hibernate/dialect/package-summary.html)
Class | Description |
---|---|
MySQLDialect | An SQL dialect for MySQL (prior to 5.x). |
MySQL5Dialect | An SQL dialect for MySQL 5.x specific features. |
MySQL55Dialect | An SQL dialect for MySQL 5.5.x specific features. |
MySQL57Dialect |
Hibernate ORM 5.3
[Package org.hibernate.dialect] (https://docs.jboss.org/hibernate/orm/5.3/javadocs/org/hibernate/dialect/package-summary.html)
Class | Description |
---|---|
MySQLDialect | An SQL dialect for MySQL (prior to 5.x). |
MySQL5Dialect | An SQL dialect for MySQL 5.x specific features. |
MySQL55Dialect | An SQL dialect for MySQL 5.5.x specific features. |
MySQL57Dialect | |
MySQL8Dialect |