2017年1月3日火曜日

Windows10にMySQL5.7をインストール

Windows10にMySQL5.7(ZIP Archive)をインストール

手元にWindows10端末が手に入ったので、さっそくMySQLをインストールしてみました。本記事はMySQL5.7をインストールした際のメモです。インストール方法についてはZIP Archiveで行います。

(1)MySQL Community Serverをダウンロード

ダウンロードページで「Windows (x86, 64-bit), ZIP Archive」をダウンロードします。

(2)ダウンロードしたファイルを解凍して配置

ダウンロードしファイルを解凍して配置します。本記事では作成場所を「C:\server\mysql\mysql-5.7.17-winx64\」とします。

(3)データフォルダの作成

データフォルダを作成します。本記事では作成場所を「C:\server\mysql\mysql-5.7.17-winx64\data\」とします。

(4)my.iniファイルの作成

my.iniファイルを作成します。本記事では作成場所を「C:\server\mysql\mysql-5.7.17-winx64\my.ini」としました。my.iniファイルの記載内容については、以下を参考にしてください。また、パスを記載する際には¥は使えないので、スラッシュを使います。
[mysqld]セクションの中には、MySQLサーバの動作に関する記述です。
[mysql]セクションには、mysql.exe(クライアントツール)の動作に関する記述です。

[mysqld]
basedir=c:/server/mysql/mysql-5.7.17-winx64/
datadir=c:/server/mysql/mysql-5.7.17-winx64/data/
character-set-server=utf8
[mysql]
default-character-set=utf8

(5)コマンドを使って初期化

管理者権限でコマンドプロンプトを起動します。本記事ではmysqldが「c:\server\mysql\mysql-5.7.17-winx64\bin」の中に入っているため、フォルダを移動します。そして、以下のコマンドを入力し、実行します。

>mysqld --initialize-insecure --console

すると、以下のようにコマンドプロンプトに表示されます。

2016-12-30T02:29:20.484733Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2016-12-30T02:29:21.113727Z 0 [Warning] InnoDB: New log files created, LSN=45790
2016-12-30T02:29:21.241187Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2016-12-30T02:29:21.339550Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: c57fd5a5-ce37-11e6-beb3-f0d5bf000ae0.
2016-12-30T02:29:21.356860Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2016-12-30T02:29:21.366678Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.

もし、以下のような内容がコマンドプロンプトに表示された場合、dataフォルダに何か入っている可能性があるため、dataフォルダの中身を空にします。

2016-12-30T02:28:57.458744Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2016-12-30T02:28:57.460749Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting.
2016-12-30T02:28:57.461752Z 0 [ERROR] Aborting

(6)MySQLを開始

コマンドプロンプトでMySQLを開始します。本記事では、サービスに登録せずに、コマンドからMySQLを起動します。(5)と同じく、mysqldが入っているフォルダまで移動し、以下のコマンドを入力します。

> mysqld --console

(7)MySQLに接続

コマンドプロンプトを起動し、以下のコマンドを入力します。(5)と同じくmysqlが入っているフォルダまで移動します。

>mysql -u root

(8)簡単な動作確認

「show databases;」などのコマンドを入力して、データベース一覧が表示されればインストールがうまくいっていると思われます。
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.10 sec)

※以下のサイトを参考にしました。あわせてご覧ください。