MySQL series: 9 storage engines

Preface

         As mentioned above, MySQL is a three-tier database system (connection layer, SQL layer, storage layer) . The storage layer is the abstract expression of data storage, which is implemented by different types of storage engines.

         MySQL adopts a hierarchical design, exposing API to support plug-in storage engine. Some general storage engines have been compiled into mysqld when MySQL is compiled and released, such as InnoDB and MyISAM. The show engines command can view the index engines supported by the system and their characteristics, as follows:

mysql> show engines;
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| Engine             | Support | Comment                                                        | Transactions | XA   | Savepoints |
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| MyISAM             | YES     | MyISAM storage engine                                          | NO           | NO   | NO         |
| CSV                | YES     | CSV storage engine                                             | NO           | NO   | NO         |
| MRG_MYISAM         | YES     | Collection of identical MyISAM tables                          | NO           | NO   | NO         |
| BLACKHOLE          | YES     | /dev/null storage engine (anything you write to it disappears) | NO           | NO   | NO         |
| PERFORMANCE_SCHEMA | YES     | Performance Schema                                             | NO           | NO   | NO         |
| InnoDB             | DEFAULT | Supports transactions, row-level locking, and foreign keys     | YES          | YES  | YES        |
| ARCHIVE            | YES     | Archive storage engine                                         | NO           | NO   | NO         |
| MEMORY             | YES     | Hash based, stored in memory, useful for temporary tables      | NO           | NO   | NO         |
| FEDERATED          | YES     | Federated MySQL storage engine                                 | NO           | NO   | NO         |
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
9 rows in set (0.00 sec)

         All storage engines supported by the author's MySQL system lock are listed above. Different storage engines have different characteristics (storage media, transaction support, backup and recovery, etc.). The most commonly used is InnoDB, which supports transactions, XA distributed transactions, savepoints, etc., and is also MySQL's default storage engine (starting with MySQL 5.5);

InnoDB overview

         InnoDB is MySQL's default storage engine, which has extremely high reliability and performance, and because of this, MySQL has become an optional solution for enterprise-level databases. The main features of MySQL are:

  1. Support affairs;
  2. Through MVCC (multi-version concurrency control) to achieve row-level locking, continuous non-locking read;
  3. Fast automatic recovery

……

       InnoDB table space

  • Similar to the concept of ORACLE, the table space is the logical storage point of data, and the physical file corresponding to the table space is the physical storage point of data . The metadata, undo log, buffer and other data of the MySQL InnoDB engine are also stored in the system tablespace by default. This tablespace can also include multiple physical files or raw partitions. Query the table space file:
mysql>  show variables like '%data_file%';
+----------------------------+------------------------+
| Variable_name              | Value                  |
+----------------------------+------------------------+
| innodb_data_file_path      | ibdata1:12M:autoextend |
| innodb_temp_data_file_path | ibtmp1:12M:autoextend  |
+----------------------------+------------------------+
2 rows in set (0.00 sec)

The above includes the default tablespace file (ibdata1) and temporary tablespace file (ibtmp1) of the InnoDB storage engine, as follows:

 

  • The default common tablespace file contains a rollback segment for storing the undo log. The undo log can be separated from the default tablespace by configuring innodb_undo_directory and innodb_undo_tablespaces. ----It has been deprecated since 5.7.13.

 

  • The InnoDB engine stores each user table in a separate tablespace file by default , and the system tablespace only stores its source data. The option innodb_file_per_table can configure this function.
mysql> show variables like '%innodb_file_per_table%';
+-----------------------+-------+
| Variable_name         | Value |
+-----------------------+-------+
| innodb_file_per_table | ON    |
+-----------------------+-------+
1 row in set (0.01 sec)

InnoDB shared table space configuration

Similar to ORACLE adding files to the table space, we can also share the table space for MySQL.

  • Increase the number of shared tablespace files

You can add the innodb_data_file_path option in the configuration file or mysqld startup options to support multiple tablespace files. The effect is as follows ( it seems to be obsolete-the experiment was unsuccessful ):

innodb_data_file_path=ibdata1:50M;ibdata2:50M:autoextend
  • The size of the table space that automatically grows, in M
mysql> show variables like '%innodb_autoextend_increment%';
+-----------------------------+-------+
| Variable_name               | Value |
+-----------------------------+-------+
| innodb_autoextend_increment | 64    |
+-----------------------------+-------+
1 row in set (0.00 sec)

Related commands

  • View the default storage engine

In addition to the show engines above, the default_storage_engine system variable also stores the default storage engine.

mysql> SELECT @@default_storage_engine;
+--------------------------+
| @@default_storage_engine |
+--------------------------+
| InnoDB                   |
+--------------------------+
1 row in set (0.00 sec)
  • View the storage engine of the table
mysql> show create table zavier.table_name;
  • The configuration file sets the default storage engine
default-storage-engine=<Storage Engine>
  • Set the storage engine for the current session
SET @@storage_engine=<Storage Engine>;
  • Specify the storage engine when creating the table
CREATE TABLE t (i INT) ENGINE = <Storage Engine>;

to sum up

As the default storage engine of MySQL, InnoDB has its unique performance and advantages. However, technology is constantly evolving, and with the continuous updating of MySQL versions, some configuration options are constantly optimized. When using it, readers need to find the ref document reference that matches their own MySQL version on the official website.

Guess you like

Origin blog.csdn.net/zhaogang1993/article/details/98777696