bigmac-jp blog

web開発関連のメモ

MySQL メモ1 InnDBとは

MySQLを使っていると一度は"InnoDB"のキーワードを聞くと思います。
InnoDBはストレージエンジンの1つで、MySQL5.5以降のデフォルトのストレージエンジンとなります。
ストレージエンジンは、SQLが解析/最適化された後に、実際のデータをストレージファイルに読み書きする処理となります。

MySQL :: MySQL 5.6 リファレンスマニュアル :: 14.1.1 デフォルトの MySQL ストレージエンジンとしての InnoDB


ストレージエンジンはInnoDB以外にもいくつかあります。
show enginesコマンドで確認した結果が下記となります。
MySQL5.7.25

mysql> show engines;
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| Engine             | Support | Comment                                                        | Transactions | XA   | Savepoints |
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| InnoDB             | DEFAULT | Supports transactions, row-level locking, and foreign keys     | YES          | YES  | YES        |
| 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         |
| CSV                | YES     | CSV storage engine                                             | NO           | NO   | NO         |
| ARCHIVE            | YES     | Archive storage engine                                         | NO           | NO   | NO         |
| PERFORMANCE_SCHEMA | YES     | Performance Schema                                             | NO           | NO   | NO         |
| FEDERATED          | NO      | Federated MySQL storage engine                                 | NULL         | NULL | NULL       |
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
9 rows in set (0.00 sec)

InnoDBを調べると比較で"MyISAM"のストレージエンジンもキーワードとしてよく出ます。

Supportカラムの"DEFAULT "は「デフォルトのストレージエンジンとして使用可能であり、現在設定されている」を表しているので、
このMySQLのデフォルトエンジンは"InnoDB"となります。
MySQL :: MySQL 5.6 リファレンスマニュアル :: 15 代替ストレージエンジン

ストレージエンジンはテーブル単位で設定が可能なため、対象テーブルのストレージエンジンは下記で確認可能です。

mysql> show table status;
+-----------+--------+---------+------------+---------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+---------------------+------------+--------------------+----------+----------------+---------+
| Name      | Engine | Version | Row_format | Rows    | Avg_row_length | Data_length | Max_data_length | Index_length | Data_free | Auto_increment | Create_time         | Update_time         | Check_time | Collation          | Checksum | Create_options | Comment |
+-----------+--------+---------+------------+---------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+---------------------+------------+--------------------+----------+----------------+---------+
| user_test | InnoDB |      10 | Dynamic    | 1047493 |             25 |    26787840 |               0 |            0 |   5242880 |        1376221 | 2019-04-03 02:13:05 | 2019-04-03 02:14:26 | NULL       | utf8mb4_general_ci |     NULL |                |         |
+-----------+--------+---------+------------+---------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+---------------------+------------+--------------------+----------+----------------+---------+
1 row in set (0.00 sec)

EngineカラムがInnoDBになっています。


用途によってストレージエンジンを選択する必要があるが、一般的なWEBシステムで使うようなTableの場合は、InnoDBで問題ないです。
トランザクションやDBパフォーマンス、可用性を考慮した場合、InnoDB以外の選択肢はないようです。