''' 数据库存储引擎是数据库底层软件组织,数据库管理系统(DBMS)使用数据引擎进行建立、查询、更新和删除数据。
不一样的存储引擎提供不一样的存储机制、索引技巧、锁定水平等功能,使用不一样的存储引擎,还能够 得到特定的功能。
如今许多不一样的数据库管理系统都支持多种不一样的数据引擎。MySQL的核心就是存储引擎。 '''
''' InnoDB: 事务性数据库的首选引擎,支持事务安全表(ACID),支持行锁和外键 MyISAM: 基于ISAM存储引擎,并对其进行扩展。它是在web、数据仓储和其余应用环境下最长使用的存储引擎之一。 拥有较高的插入、查询速度,但不支持事务 支持表锁 Memory: 将表中的数据存储到内存中,未查询和引用其余数据提供快速访问 每一个表能够有多达32个索引,每一个索引16列,以及500字节的最大键长度
存储引擎是基于表的,而不是基于库的。因此存储引擎也可被称为表类型。 '''
存储引擎的特色及分类mysql
show engines;web
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+ | 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 | +--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
show variables like '%storage_engine%';sql
+----------------------------------+--------+ | Variable_name | Value | +----------------------------------+--------+ | default_storage_engine | InnoDB | | default_tmp_storage_engine | InnoDB | | disabled_storage_engines | | | internal_tmp_disk_storage_engine | InnoDB | +----------------------------------+--------+
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
使用ALERT TABLE修改表的存储引擎可能致使数据库中的数据丢失,因此在修改前,须要备份数据(通常不建议修改)安全
alter table 表名 engine=存储引擎名称app
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