LoginSignup
6
9

More than 5 years have passed since last update.

MySQL 8.0をWindows10へzipでインストール

Last updated at Posted at 2018-11-07

MySQLを某勉強会で使うので、Windows10 Homeへzip形式でインストールしたときの手順
※ 勝手に予習してる内容なので勉強会内での手順と異なる場合があります

MySQL: https://www.mysql.com/

zipのダウンロード

2018.11.07時点ではzipのダウンロードは以下の通り

  • [DOWNLOADS]
  • -> 下部の[Community (GPL) Downloads]
  • -> 中央付近にある"MySQL on Windows (Installer & Tools) "でなく、[MySQL Community Server]
  • -> 下部のOther Downloadsのとこにある「Windows (x86, 64-bit), ZIP Archive」の[Download]
  • -> ログイン画面になるけど、下部の[No thanks, just start my download.]でzipダウンロード開始

image.png

image.png

image.png

image.png

image.png

セットアップ

インストーラを使用しないzipインストールのドキュメントはこちら。

MySQL :: MySQL 8.0 Reference Manual :: 2.3.5 Installing MySQL on Microsoft Windows Using a noinstall ZIP Archive

zipの展開

どこでもいいんだけれど、念のためにスペースや日本語を含まないパスへ。
今回はC:\local\mysql-8.0.13-winx64へ。

ドキュメントを見る限りではC:\Program Files\MySQLでもよさそう。

設定ファイルの作成

以下の内容でMySQLを展開した場所にC:\local\mysql-8.0.13-winx64\my.iniを作成する

my.ini
[mysqld]
# set basedir to your installation path
basedir=C:/local/mysql-8.0.13-winx64
# set datadir to the location of your data directory
datadir=C:/local/var/mysqldata

basedirはMySQLをインストールした場所。
datadirはDBのデータを置く場所。指定のパスにディレクトリを作成しておく。

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

https://dev.mysql.com/doc/refman/8.0/en/windows-initialize-data-directory.html
https://dev.mysql.com/doc/refman/8.0/en/data-directory-initialization-mysqld.html

コマンドプロンプトを起動して、MySQLをインストールしたディレクトリへ移動

C:\Users\zaki>cd C:\local\mysql-8.0.13-winx64

C:\local\mysql-8.0.13-winx64>

初期化コマンドを実行

C:\local\mysql-8.0.13-winx64>bin\mysqld --initialize --console
2018-11-07T13:24:12.714689Z 0 [System] [MY-013169] [Server] C:\local\mysql-8.0.13-winx64\bin\mysqld.exe (mysqld 8.0.13) initializing of server in progress as process 12964
2018-11-07T13:24:19.141134Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: ********
2018-11-07T13:24:22.306672Z 0 [System] [MY-013170] [Server] C:\local\mysql-8.0.13-winx64\bin\mysqld.exe (mysqld 8.0.13) initializing of server has completed

実行すると、「temporary password~~」のところにパスワードが表示されるのでメモっておく。
また、my.iniファイルのdatadirに指定したディレクトリにデータファイルが多数作成されるので、ファイルが存在することを確認する。

MySQLサーバの起動

パスワードの設定が次の手順にあるけど、設定するためにはMySQLを先に起動しないといけない。(ドキュメントちょっと読みにくいなw)

C:\local\mysql-8.0.13-winx64> bin\mysqld --console
2018-11-07T13:39:14.928628Z 0 [System] [MY-010116] [Server] C:\local\mysql-8.0.13-winx64\bin\mysqld.exe (mysqld 8.0.13) starting as process 9260
2018-11-07T13:39:17.390529Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2018-11-07T13:39:17.487625Z 0 [System] [MY-010931] [Server] C:\local\mysql-8.0.13-winx64\bin\mysqld.exe: ready for connections. Version: '8.0.13'  socket: ''  port: 3306  MySQL Community Server - GPL.
2018-11-07T13:39:17.560250Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060

image.png

起動処理中に、例によってWindowsファイアウォールの警告が表示されると思うのでアクセスを許可する。

ready for connectionsと表示されたら起動OK

パスワード設定

MySQLを起動したコマンドプロンプトはMySQL実行中でとりあえず使えないので、もう一つコマンドプロンプトを起動し、ディレクトリを移動する

Microsoft Windows [Version 10.0.17134.345]
(c) 2018 Microsoft Corporation. All rights reserved.

C:\Users\zaki>cd C:\local\mysql-8.0.13-winx64

C:\local\mysql-8.0.13-winx64>

以下のコマンドを実行
bin\mysql -u root -p

するとパスワードを聞いてくるので、初期化時に表示されたパスワードを入力する。

C:\local\mysql-8.0.13-winx64>bin\mysql -u root -p
Enter password: ************
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.13

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.

mysql>

プロンプトがmysql>に変わったら、次のコマンドを実行してパスワードを設定
(この実行例だと、パスワードはroot-passwordになる。思いっきり画面に表示されるのでショルダーハックに注意)

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'root-password';
Query OK, 0 rows affected (0.04 sec)

mysql>

コンソールを抜ける

mysql> exit
Bye

※ これは操作を終わるだけ。MySQLサーバは実行したまま。

MySQLサーバの停止

MySQLを起動しっぱなしのコマンドプロンプトで、Ctrl-Cをタイプする

^C
C:\local\mysql-8.0.13-winx64>2018-11-07T13:56:45.123815Z 0 [System] [MY-010910] [Server] C:\local\mysql-8.0.13-winx64\bin\mysqld.exe: Shutdown complete (mysqld 8.0.13)  MySQL Community Server - GPL.

C:\local\mysql-8.0.13-winx64>

すると停止する

PATHの追加

今のままだと、mysqlのコマンド名だけで実行できないので、環境変数を追加する

PCを右クリックしてプロパティを起動
image.png

システムの詳細設定
image.png

[環境変数(N)]ボタンを押下
image.png

「システム環境変数」の「Path」の行を選択して[編集(I)]ボタンを押下
image.png

[新規(N)]ボタン押下
image.png

すると最後の行へ設定のテキスト入力状態になるので、MySQLをインストールしたディレクトリの下にあるbinディレクトリのパスを入力する。
image.png
image.png

あとはOKで画面を閉じていく。

これ以降新しく起動したコマンドプロンプトからは、パスの指定不要でMySQLのコマンドが使用できるようになる。

C:\Users\zaki>mysqld --console
2018-11-07T14:12:29.458091Z 0 [System] [MY-010116] [Server] C:\local\mysql-8.0.13-winx64\bin\mysqld.exe (mysqld 8.0.13) starting as process 9612
2018-11-07T14:12:30.300697Z 0 [System] [MY-010229] [Server] Starting crash recovery...
2018-11-07T14:12:30.339499Z 0 [System] [MY-010232] [Server] Crash recovery finished.
2018-11-07T14:12:31.448031Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2018-11-07T14:12:31.516241Z 0 [System] [MY-010931] [Server] C:\local\mysql-8.0.13-winx64\bin\mysqld.exe: ready for connections. Version: '8.0.13'  socket: ''  port: 3306  MySQL Community Server - GPL.
2018-11-07T14:12:31.536121Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060

タイムゾーンの設定

※ あれ?この設定不要? 設定してもmysqld --consoleの時刻はUTCのままだし、変更前でもselect curtime();の値はJSTになってる…いちおう設定したので手順を残しておく

https://dev.mysql.com/doc/refman/8.0/en/time-zone-support.html
デフォルトだとUTCになっている?ので日本時間と9時間ズレてるので、タイムゾーン設定する。

https://dev.mysql.com/downloads/timezones.html
まずタイムゾーンファイルをダウンロードする(ここからっ!?)

image.png

ここの"5.7+"の"POSIX standard"のzipをダウンロードする。(他のは試してない)
zipの中はtimezone_posix.sqlファイル(テキストファイル)が一つ含まれているだけなので、どこでもいいので取り出す(Downloadsフォルダのままでよい)

まずMySQLサーバが起動していなければ起動する

C:\Users\zaki>mysqld --console

次に別のコマンドプロンプトでtimezone_posix.sqlがあるディレクトリへ移動する。

C:\Users\zaki>cd Downloads

C:\Users\zaki\Downloads>

次のコマンドを実行する
mysql -u root -p mysql < ダウンロードしたSQLファイル

C:\Users\zaki\Downloads>mysql -u root -p mysql < timezone_posix.sql
Enter password: ******** (設定済みのrootパスワード)

C:\Users\zaki\Downloads>

設定ファイルに以下タイムゾーンの設定を追加

# timezone
default-time-zone = 'Asia/Tokyo'

MySQLを再起動する

C:\Users\zaki>mysqld --console
2018-11-07T14:59:57.522997Z 0 [System] [MY-010116] [Server] C:\local\mysql-8.0.13-winx64\bin\mysqld.exe (mysqld 8.0.13) starting as process 12396
2018-11-07T14:59:59.383907Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2018-11-07T14:59:59.452232Z 0 [System] [MY-010931] [Server] C:\local\mysql-8.0.13-winx64\bin\mysqld.exe: ready for connections. Version: '8.0.13'  socket: ''  port: 3306  MySQL Community Server - GPL.
2018-11-07T14:59:59.481844Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060

あれ?時刻はUTCのままだ。。

コマンドラインツール

mysqlコマンドでサーバへ接続してコマンドラインでSQLをたたく。
-pがないとパスワードを聞かれないため認証エラーになる。

C:\Users\zaki>mysql -u root -p
Enter password: ********
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.13 MySQL Community Server - GPL

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.

mysql>

終了するにはquit

mysql> quit
Bye

C:\Users\zaki>
6
9
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
6
9