mysql存储引擎

'''
数据库存储引擎是数据库底层软件组织,数据库管理系统(DBMS)使用数据引擎进行创建、查询、更新和删除数据。
不同的存储引擎提供不同的存储机制、索引技巧、锁定水平等功能,使用不同的存储引擎,还可以 获得特定的功能。
现在许多不同的数据库管理系统都支持多种不同的数据引擎。MySQL的核心就是存储引擎。
'''

一、常见存储引擎简介

'''
InnoDB:
    事务性数据库的首选引擎,支持事务安全表(ACID),支持行锁和外键

MyISAM:
    基于ISAM存储引擎,并对其进行扩展。它是在web、数据仓储和其他应用环境下最长使用的存储引擎之一。
    拥有较高的插入、查询速度,但不支持事务
    支持表锁
Memory:
    将表中的数据存储到内存中,未查询和引用其他数据提供快速访问
    每个表可以有多达32个索引,每个索引16列,以及500字节的最大键长度
存储引擎是基于表的,而不是基于库的。所以存储引擎也可被称为表类型。
'''

存储引擎的特点及分类

二、存储引擎查看

1、查看数据库支持的存储引擎

show engines;

+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| Engine             | Support | Comment                                                        | Transactions | XA   | Savepoints |
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| MyISAM             | YES     | MyISAM storage engine                                          | NO           | NO   | NO         |
| CSV                | YES     | CSV storage engine                                             | NO           | NO   | NO         |
| PERFORMANCE_SCHEMA | YES     | Performance Schema                                             | NO           | NO   | NO         |
| BLACKHOLE          | YES     | /dev/null storage engine (anything you write to it disappears) | NO           | NO   | NO         |
| MRG_MYISAM         | YES     | Collection of identical MyISAM tables                          | 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          | NO      | Federated MySQL storage engine                                 | NULL         | NULL | NULL       |
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
View Code

2、查看当前数系统使用的存储引擎

show variables like '%storage_engine%';

+----------------------------------+--------+
| Variable_name                    | Value  |
+----------------------------------+--------+
| default_storage_engine           | InnoDB |
| default_tmp_storage_engine       | InnoDB |
| disabled_storage_engines         |        |
| internal_tmp_disk_storage_engine | InnoDB |
+----------------------------------+--------+
View Code

3、查看建表是使用的存储引擎

show create table 表名;

*************************** 1. row ***************************
       Table: proxycode
Create Table: CREATE TABLE `proxycode` (
  `proxycode` int(10) unsigned NOT NULL COMMENT '合法代理编码',
  PRIMARY KEY (`proxycode`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
View Code

三、修改指定表的存储引擎

使用ALERT TABLE修改表的存储引擎可能导致数据库中的数据丢失,所以在修改前,需要备份数据(一般不建议修改)

alter table 表名 engine=存储引擎名称

mysql> alter table student engine=innodb
;
Query OK, 0 rows affected
Records: 0  Duplicates: 0  Warnings: 0

mysql> show create table student;
+---------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table   | Create Table                                                                                                                                                                                                                                      |
+---------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| student | CREATE TABLE `student` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(10) NOT NULL DEFAULT '' COMMENT '姓名',
  `address` varchar(64) CHARACTER SET utf8 NOT NULL DEFAULT '',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 |
+---------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set
alter table student engine=innodb
原文地址:https://www.cnblogs.com/lichunke/p/9754175.html