2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

MySQL Community Server 5.6 - Installing on Windows 7

Last updated at Posted at 2015-06-19

概要

Windows7に開発・検証目的用にMySQL Community Server 5.6をインストールし、初歩的な設定を行うまでの作業メモです。
MySQLはZIP Archiveを使用します。

環境

この記事の内容は下記のバージョンで動作確認を行いました。

  • Windows7 (64bit)
  • MySQL Community Server 5.6.25

参考サイト

下記のサイトの内容を参考にしました。

インストール

アーカイブファイルのダウンロード

ダウンロードページよりアーカイブファイルをダウンロードします。
今回ダウンロードしたファイルはmysql-5.6.25-winx64.zipです。

アーカイブファイルの展開

アーカイブファイルを適当な場所(D:/dev/mysql-5.6.25-winx64にしました)へ展開します。
また、次のディレクトリを作成します。

  • D:/dev/mysql-5.6.25-winx64/logs
  • D:/dev/mysql-5.6.25-winx64/tmp

my.iniの準備

D:/dev/mysql-5.6.25-winx64/my-default.iniというテンプレートファイルをmy.iniへリネームし、下記のように修正します。

my.ini
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/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
+ innodb_buffer_pool_size = 64M
+ innodb_file_per_table = 1
+ innodb-status-output = 1
+ innodb-status-output-locks = 1
+ 
+ default-storage-engine = innodb

# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
- # log_bin
+ log_bin = mysql-bin

# These are commonly set, remove the # and set as required.
- # basedir = .....
- # datadir = .....
- # port = .....
- # server_id = .....
+ basedir = "D:/dev/mysql-5.6.25-winx64"
+ datadir = "D:/dev/mysql-5.6.25-winx64/data"
+ tmpdir  = "D:/dev/mysql-5.6.25-winx64/tmp"
+ port = 3306
+ server_id = 1
+ 
+ character-set-server = utf8
+ collation-server = utf8_general_ci
+ 
+ transaction-isolation = REPEATABLE-READ
+ 
+ # Logging
+ log_output = FILE
+ log_warnings = 1
+ log_error = "D:/dev/mysql-5.6.25-winx64/logs/mysqld_error.log
+ general_log = 1
+ general_log_file = "D:/dev/mysql-5.6.25-winx64/logs/general_query_all.log"
+ log-slow-admin-statements = 1
+ log-queries-not-using-indexes = 1
+ slow_query_log = 1
+ long_query_time = 1
+ slow_query_log_file = "D:/dev/mysql-5.6.25-winx64/logs/slow_query.log"
+ 

# 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 
+ 
+ #autocommit = 0
+ explicit_defaults_for_timestamp = true
+ 
+ [mysql]
+ default-character-set = utf8
+ show-warnings

mysql serverの起動と接続

起動

startup
> D:\dev\mysql-5.6.25-winx64\bin\mysqld.exe --defaults-file=D:\dev\mysql-5.6.25-winx64\my.ini --console

rootユーザーでログイン

login
> D:\dev\mysql-5.6.25-winx64\bin\mysql.exe -u root -p

停止

shutdown
> D:\dev\mysql-5.6.25-winx64\bin\mysqladmin.exe -u root -p shutdown

mysqldのオプションの確認と設定値の出力
(結果が長いのでtextファイルに出力しています。)

option
> D:\dev\mysql-5.6.25-winx64\bin\mysqld.exe --help --verbose > option_dump.txt

インストール後の設定

rootユーザーのパスワード設定

rootユーザーでログイン

login
> D:\dev\mysql-5.6.25-winx64\bin\mysql.exe -u root -p

rootユーザーのパスワードを変更(パスワードは伏せています)

change_password
mysql> set password for 'root'@'localhost' = password('******');

不要なユーザーの削除

使用しないユーザーは削除します。

drop_user
mysql> drop user ''@'localhost';
mysql> drop user 'root'@'127.0.0.1'
mysql> drop user 'root'@'::1'

コマンド実行サンプル

データベース

データベースの一覧

show
mysql> show databases;

データベースの作成

create_database
mysql> create database if not exists sample_db
default character set utf8
default collate utf8_general_ci;

[Manual - CREATE DATABASE Syntax] (http://dev.mysql.com/doc/refman/5.6/en/create-database.html)

データベースの削除

drop_database
mysql> drop database sample_db;

カレントデータベースの変更

use
mysql> use sample_db

INNODB

mysql> show engine innodb status;
variables
mysql> show variables like "innodb%";

ユーザーの作成と権限の付与

ユーザーの確認

mysql> select user,host from mysql.user;

ユーザーの作成

create_user
mysql> create user 'test_user'@'localhost' identified by 'test_user';

[Manual - CREATE USER Syntax] (http://dev.mysql.com/doc/refman/5.6/en/create-user.html)

ユーザーの削除

drop_user
mysql> drop user 'test_user'@'localhost';

ユーザーへ権限の付与

grant
mysql> grant all on sample_db.* to 'test_user'@'localhost';

[Manual - GRANT Syntax] (http://dev.mysql.com/doc/refman/5.6/en/grant.html)

ユーザーの権限を取り消す

revoke
mysql> revoke insert on sample_db.* from 'test_user'@'localhost'

ユーザーの権限をすべて取り消す

revoke
mysql> revoke all privileges, grant option from 'test_user'@'localhost';

[Manual - REVOKE Syntax] (http://dev.mysql.com/doc/refman/5.6/en/revoke.html)

ユーザーの権限を確認

grants
mysql> show grants for 'test_user'@'localhost'

現在接続しているユーザーの権限を確認

grants
mysql> show grants;

[Manual - SHOW GRANTS Syntax] (http://dev.mysql.com/doc/refman/5.6/en/show-grants.html)

テーブル

テーブルの一覧

tables
mysql> show tables;

テーブルの作成

create_table
mysql> create table if not exists sample_tbl (
  id int(11) not null auto_increment,
  name varchar(20),
  primary key(id)
);

[Manual - CREATE TABLE Syntax] (http://dev.mysql.com/doc/refman/5.6/en/create-table.html)

テーブル定義の確認

desc
mysql> desc sample_tbl;

カラムの追加

alter_table
mysql> alter table sample_tbl add column address varchar(256);

カラムの削除

alter_table
mysql> alter table sample_tbl drop column address;

テーブルの削除

drop_table
mysql> drop table sample_tbl;

インデックス

インデックスの一覧

show_index
mysql> show index from sample_tbl;

インデックスの作成

create_index
mysql> create index sample_tbl_idx01 on sample_tbl(address(64) asc);

[Manual - CREATE INDEX Syntax] (http://dev.mysql.com/doc/refman/5.6/en/create-index.html)

インデックスの削除

drop_index
mysql> drop index sample_tbl_idx01 on sample_tbl;

キャラクターセット

利用できるキャラクターセットの一覧

character_set
mysql> show character set;

一部抜粋です。

|Charset |Description | |
|:---------|:----------------------------+---------------------|
|cp850 | DOS West European | |
|latin1 | cp1252 West European | |
|latin2 | ISO 8859-2 Central European | |
|ascii | US ASCII | |
|ujis | EUC-JP Japanese | |
|sjis | Shift-JIS Japanese | |
|greek | ISO 8859-7 Greek | |
|cp1250 | Windows Central European | |
|latin5 | ISO 8859-9 Turkish | |
|utf8 | UTF-8 Unicode | |
|ucs2 | UCS-2 Unicode | |
|cp852 | DOS Central European | |
|latin7 | ISO 8859-13 Baltic | |
|utf8mb4 | UTF-8 Unicode | |
|utf16 | UTF-16 Unicode | |
|utf16le | UTF-16LE Unicode | |
|cp1256 | Windows Arabic | |
|cp1257 | Windows Baltic | |
|utf32 | UTF-32 Unicode | |
|cp932 | SJIS for Windows Japanese | |
|eucjpms | UJIS for Windows Japanese | |

variables
mysql> show variables like "char%";
+--------------------------+--------------------------------------------+
| Variable_name            | Value                                      |
+--------------------------+--------------------------------------------+
| character_set_client     | utf8                                       |
| character_set_connection | utf8                                       |
| character_set_database   | utf8                                       |
| character_set_filesystem | binary                                     |
| character_set_results    | utf8                                       |
| character_set_server     | utf8                                       |
| character_set_system     | utf8                                       |
| character_sets_dir       | D:\dev\mysql-5.6.25-winx64\share\charsets\ |
+--------------------------+--------------------------------------------+
8 rows in set (0.00 sec)

その他

環境変数

variables
mysql> show variables;
variables
mysql> show variables like "slow%";
+---------------------+------------------------------------------------+
| Variable_name       | Value                                          |
+---------------------+------------------------------------------------+
| slow_launch_time    | 2                                              |
| slow_query_log      | ON                                             |
| slow_query_log_file | D:/dev/mysql-5.6.25-winx64/logs/slow_query.log |
+---------------------+------------------------------------------------+
3 rows in set (0.00 sec)
variables
mysql> select @@slow_query_log_file;
+------------------------------------------------+
| @@slow_query_log_file                          |
+------------------------------------------------+
| D:/dev/mysql-5.6.25-winx64/logs/slow_query.log |
+------------------------------------------------+
1 row in set (0.00 sec)

status

mysql> status

help

mysql> help
2
2
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
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?