MySQL database storage engine on those things

If you want to modify MySQL database storage engine, it must be understood that both engines, and clearly understand the difference between the two engines.

MySQL database storage engine supports two common:

InnoDB engine: provides support for ACID transactions database, and SQL standards to achieve the four isolation levels. The engine also provides row-level locking, and foreign key constraint, it is designed to handle high-capacity database system, which itself is actually a complete database system based on MySQL backend, MySQL runtime Innodb will create a buffer pool in memory for buffering data and indexes. But the engine does not support FULLTEXT index type, and it does not hold the number of rows in the table, when SELECT COUNT (*) FROM TABLE when the need to scan the entire table. When you need to use a database transaction, the engine is the preferred course. Since the lock granularity is smaller, the write operation does not lock the entire table, so when high concurrency, use Innodb engine will improve efficiency. However, row-level locking is not absolute, if MySQL can not determine the range to be scanned in the implementation of a SQL statement, InnoDB table will also lock the whole table.

MyIASM engine: is MySQL default engine, but it does not provide support for database transactions, does not support row-level locking, and foreign keys, so that is a write operation when INSERT (insert) or UPDATE (update) data need to lock the entire table, efficiency will be lower. However, different and Innodb, MyIASM stored in rows in the table, then SELECT COUNT (*) FROM TABLE when only has to read the saved value directly without the need for a full table scan. If the table is read much more than write operations and does not require database transaction support, then MyIASM is a good choice.

The main difference:
. 1, MyIASM non-transactional security and InnoDB is transaction safe;
2, MyIASM lock granularity table level, and InnoDB supports row-level locks;
. 3, MyIASM supports text type index, InnoDB does not support full-text index ;
4, MyIASM relatively simple, the efficiency is better than InnoDB, a small application, consider using MyIASM;
5, save MyIASM table into a file format, cross-platform easier to use.

Application scenarios:
1, MyIASM manage non-transactional table, providing high-speed storage and retrieval, and full-text search capability, perform a number of operations if we select applications, should choose MyIASM
characteristics 2, InnoDB for transactions with ACID transaction support, etc., if the insert and update operations perform a large number of applications, should choose InnoDB

View engine information mysql database

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

Support column, YES indicates that the current version supports the storage engine, DEFAULT indicates that the engine is the default engine. NO indicates that the corresponding storage engine.
Viewing System Variables default_storage_engine or storage_engine

mysql> show variables like '%storage_engine%';
+----------------------------+--------+
| Variable_name              | Value  |
+----------------------------+--------+
| default_storage_engine     | InnoDB |
| default_tmp_storage_engine | InnoDB |
| storage_engine             | InnoDB |
+----------------------------+--------+
3 rows in set (0.00 sec)

default_storage_engine represents a permanent table (permanent tables) by default storage engine. ;
Default_tmp_storage_engine indicates the default storage engine temporary tables;
storage_engine this system variable is not recommended, it has been replaced by a system variable default_storage_engine.

Modify the default MySQL database storage engine

[root@localhost ~]# vim /etc/my.cnf                       //编写mysql服务的主配置文件
               ………………         //省略部分内容,添加如下内容
default-storage-engine=MyISAM
[root@localhost ~]# systemctl restart mysqld            //重新启动mysql服务
mysql> show engines;
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| Engine             | Support | Comment                                                        | Transactions | XA   | Savepoints |
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| FEDERATED          | NO      | Federated MySQL storage engine                                 | NULL         | NULL | NULL       |
| MRG_MYISAM         | YES     | Collection of identical MyISAM tables                          | NO           | NO   | NO         |
| MyISAM             | DEFAULT | MyISAM storage engine                                          | NO           | NO   | NO         |
| BLACKHOLE          | YES     | /dev/null storage engine (anything you write to it disappears) | NO           | NO   | NO         |
| CSV                | YES     | CSV storage engine                                             | NO           | NO   | NO         |
| MEMORY             | YES     | Hash based, stored in memory, useful for temporary tables      | NO           | NO   | NO         |
| ARCHIVE            | YES     | Archive storage engine                                         | NO           | NO   | NO         |
| InnoDB             | YES     | Supports transactions, row-level locking, and foreign keys     | YES          | YES  | YES        |
| PERFORMANCE_SCHEMA | YES     | Performance Schema                                             | NO           | NO   | NO         |
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
9 rows in set (0.00 sec)
//再次查看发现MyISAM引擎已经成为默认引擎

Directly modify the default storage engine mysql database

mysql> set default_storage_engine=InnoDB;
Query OK, 0 rows affected (0.00 sec)

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

Note that this system variable default_storage_engine is BOTH (global and temporary), and can be dynamically modified. But be careful, even if you change the system variable default_storage_engine, after the restart will fail, if you want to permanently modify, it is best to set the value of default-storage-engine in the my.cnf configuration file inside.

Review the default engine used by the table

mysql> show create table t1 \G;
*************************** 1. row ***************************
       Table: t1
Create Table: CREATE TABLE `t1` (
  `id` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8
1 row in set (0.00 sec
//可以看出t1表默认使用的引擎是MyISAM。

Modify the default storage engine tables

mysql> ALTER TABLE t1 ENGINE = InnoDB;
Query OK, 0 rows affected (0.01 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> show create table t1 \G;
*************************** 1. row ***************************
       Table: t1
Create Table: CREATE TABLE `t1` (
  `id` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8
1 row in set (0.00 sec)
//可以看出t1表默认使用的引擎是InnoDB。

Create table when the specified storage engine
to create the table when, if you want to specify a storage engine, only need to set the parameters ENGINE.

mysql> create table t2 (id int) engine=InnoDB;
Query OK, 0 rows affected (0.00 sec)

mysql> create table t3 (id int) engine=MyISAM;
Query OK, 0 rows affected (0.00 sec)

Guess you like

Origin blog.51cto.com/14157628/2422733