LoginSignup
45
29

More than 5 years have passed since last update.

MySQLサーバのストレージエンジン確認方法

Last updated at Posted at 2017-01-24

はじめに

完全に自分用の備忘録です。
年末年始の纏まった時間にSQLやMySQLサーバの勉強を始めたので、勉強した内容を少しずつ残して行こうと思います。

同じネタはインターネット上に山ほど転がっているので車輪の再発明どころか車輪の過剰生産といった感じですが、用語集と詳細なコマンド実行結果をつけてお得感を出してみました。

用語集

データベース管理システム:
 MySQLとかMariaDBとか、いわゆるDBサーバと呼ばれるミドルウェア達のことです
データベース:
 テーブルの集まり。Excelでいう「ブック」を想像すると良いと思います。
テーブル:
 構造化されたデータの集まり。Excelでいう「シート」を想像すると良いと思います。

※Excelに例えてしまう初級者を優しい目で見てあげて下さい

SQL:
 データベース管理システムを操作するための言語
ストレージエンジン:
 テーブルのデータを読み書きするための仕組み。
 同じデータベース内でもテーブル毎に異なるストレージエンジンをもつことができる。

ストレージエンジンについてもう少し

デフォルトのストレージエンジン

MySQLサーバのデフォルトストレージエンジンは設定ファイルで規定され、記述が無い場合はバージョン次第。show engines;で確認することができる。下記の例だとデフォルトはInnoDBになっている。

MariaDB [(none)]> show engines;
+--------------------+---------+----------------------------------------------------------------------------+--------------+------+------------+
| Engine             | Support | Comment                                                                    | Transactions | XA   | Savepoints |
+--------------------+---------+----------------------------------------------------------------------------+--------------+------+------------+
| CSV                | YES     | CSV storage engine                                                         | NO           | NO   | NO         |
| MRG_MYISAM         | YES     | Collection of identical MyISAM tables                                      | NO           | NO   | NO         |
| MEMORY             | YES     | Hash based, stored in memory, useful for temporary tables                  | NO           | NO   | NO         |
| BLACKHOLE          | YES     | /dev/null storage engine (anything you write to it disappears)             | NO           | NO   | NO         |
| MyISAM             | YES     | MyISAM storage engine                                                      | NO           | NO   | NO         |
| InnoDB             | DEFAULT | Percona-XtraDB, Supports transactions, row-level locking, and foreign keys | YES          | YES  | YES        |
| ARCHIVE            | YES     | Archive storage engine                                                     | NO           | NO   | NO         |
| FEDERATED          | YES     | FederatedX pluggable storage engine                                        | YES          | NO   | YES        |
| PERFORMANCE_SCHEMA | YES     | Performance Schema                                                         | NO           | NO   | NO         |
| Aria               | YES     | Crash-safe tables with MyISAM heritage                                     | NO           | NO   | NO         |
+--------------------+---------+----------------------------------------------------------------------------+--------------+------+------------+
10 rows in set (0.00 sec)

MariaDB [(none)]>

既存のTableのストレージエンジン

作成済のTableに紐づいているエンジンはinformation_schemaというデータベース内のtableというテーブルに保存されている。同テーブルのtable_schemaがデータベース名、table_nameがテーブル名、engineが使用するストレージエンジン名です。文章だと何のことだか分からないので実際にやってみます。

ログイン

[root@localhost ~]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 5
Server version: 5.5.52-MariaDB MariaDB Server

Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>

rootパスワーd...(∩゚д゚)アーアーキコエナーイ
自習用なので優しい目で見てあげてください。

Jinnai73_Qiitaの下にTest1を作成

MariaDB [(none)]> create database Jinnai73_Qiita;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| Jinnai73_Qiita     |
| mysql              |
| performance_schema |
| test               |
+--------------------+
5 rows in set (0.00 sec)

MariaDB [(none)]> use Jinnai73_Qiita
Database changed
MariaDB [Jinnai73_Qiita]> create table Test1 (id int, name varchar(32));
Query OK, 0 rows affected (0.05 sec)

MariaDB [Jinnai73_Qiita]> show tables;
+--------------------------+
| Tables_in_Jinnai73_Qiita |
+--------------------------+
| Test1                    |
+--------------------------+
1 row in set (0.00 sec)

MariaDB [Jinnai73_Qiita]>

できました。

ストレージエンジンを確認

MariaDB [Jinnai73_Qiita]> use information_schema;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [information_schema]> select table_schema, table_name, engine from tables where table_schema = 'Jinnai73_Qiita';
+----------------+------------+--------+
| table_schema   | table_name | engine |
+----------------+------------+--------+
| Jinnai73_Qiita | Test1      | InnoDB |
+----------------+------------+--------+
1 row in set (0.00 sec)

MariaDB [information_schema]>

ちゃんとInnoDBになっていました。

おわりに

しばらくは他の勉強と並行してSQL(とMySQL)の勉強をしていきたいと思います。ずっとDBサーバ恐怖症だったのですが、SQLの勉強が思いのほか楽しいです。


(2017/5/20追記)
「SQLサーバ」はMicrosoft製品「SQL Server」のことになってしまうため、「MySQLサーバ」に修正しました。ご指摘ありがとうございますm(_ _)m

45
29
2

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
45
29