2019年8月4日日曜日

MySQL 5.7.27(ZIP板)をWindows7にセットアップ

概要

複数PCにMySQLのセットアップが必要な場合、データコピーだけで構築できると便利が良い。
過去に構築した環境がいい加減古くなったので、最新バージョンで再構築する。
バージョン選定の際、最新の8.0系にするか迷った。
8.0系は速度が魅力的だが、現システムでは速度が必要でない為、安定重視で5.7系を採用とした。
構築にあたり、戸惑う部分が多く、思ったよりも情報が少なく感じた為、備忘録として残しておく。

・環境

MySQL:MySQL Community Server 5.7.27
OS:Windows 7 32bit


「Windows (x86, 32-bit), ZIP Archive」をダウンロード

以下urlより、zipファイルをダウンロード

url:https://dev.mysql.com/downloads/mysql/5.7.html#downloads


ダウンロードしたzipをd:\に解凍

zipを解凍するが、「my-default.ini」ファイルがない。
どうやら「5.7.18」から無くなったようだ。



my-default.ini」ファイル入手

ダウンロードした、5.7.17のzipを解凍し、「my-default.ini」を入手した。
しかし、シンプルすぎてあまり参考にならなかった。
これなら、過去のmy.iniを再加工しても良いかもしれない。


・my-default.ini
--------------------------------------------------------------------
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.

[mysqld]


# Remove leading # and set to the amount of RAM for the most important data

# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M

# Remove leading # to turn on a very important data integrity option: logging

# changes to the binary log between backups.
# log_bin

# These are commonly set, remove the # and set as required.

# basedir = .....
# datadir = .....
# port = .....
# server_id = .....


# Remove leading # to set options mainly useful for reporting servers.

# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M 


sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 
--------------------------------------------------------------------


my.ini」ファイルの作成

「my-default.ini」の記載を変更し、「my.ini」に変更した。
basedir、datadirの2行を変更している。
「basedir」は、MySQLのフォルダを指定し、「datadir」は、MySQLフォルダのdataフォルダを指定した。(この時点でdataフォルダは存在しない)
また、実際には「\」は¥マークで記載している。


・my.ini
--------------------------------------------------------------------
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.

[mysqld]


# Remove leading # and set to the amount of RAM for the most important data

# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M

# Remove leading # to turn on a very important data integrity option: logging

# changes to the binary log between backups.
# log_bin

# These are commonly set, remove the # and set as required.

basedir = D:\mysql-5.7.27-win32
datadir = D:\mysql-5.7.27-win32\data
#port = .....
# server_id = .....


# Remove leading # to set options mainly useful for reporting servers.

# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M 

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 
--------------------------------------------------------------------


「data」フォルダの初期化

コマンドプロンプトで以下コマンド実行し、dataフォルダに初期データを作成する。

D:\mysql-5.7.27-win32\bin>mysqld --defaults-file=D:\mysql-5.7.27-win32\my.ini --
initialize

コマンドを実行すると、dataフォルダ・初期データが作成される。




rootユーザーのパスワード変更

最近のMySQLは初期ユーザーrootにランダムなパスワードが設定されているようだ。
「data」フォルダの「[コンピュータ名].err」ファイルにランダムに生成されたパスワードがある。
実際には、以下のように記載があり、「H4:tF6voe5?=」がrootの初期パスワードである。

[コンピュータ名].err

--------------------------------------------------------------------

2019-08-04T01:59:18.424458Z 1 [Note] A temporary password is generated for root@localhost: H4:tF6voe5?=

--------------------------------------------------------------------

参考:MySQLインストール直後にログインできない場合の対処



サービス登録

以下サイトを参考にWindowsサービスとして登録した。
サービスとして登録しておけば、再起動後も自動的に起動する。

参考:MySQLをWindowsサービスに登録する



以上で、環境構築は完了。

あとは、データを投入後、フォルダごと他のPCにコピー・サービス登録を行えば、他のPCでも使えるようになる。

0 件のコメント: