mysql存储引擎简介_MySQL存储引擎简介

MySQL支持多种存储引擎,如InnoDB、MyISAM、Memory等,各有特点。InnoDB支持事务处理和外键,适合需要高并发和数据一致性的场景;MyISAM访问速度快,但不支持事务。Memory引擎将数据存储在内存中,适用于临时表。默认从5.5.5版本起,MySQL使用InnoDB作为默认存储引擎。用户可以通过SQL语句或配置文件更改默认引擎和指定表的存储引擎。
摘要由CSDN通过智能技术生成

存储引擎(Storage Engine)是处理不同类型的表的SQL操作的MySQL部件,也被称为表类型。 MySQL支持多种的存储引擎,比如最新的MySQL 5.6就支持InnoDB、MyISAM、Memory、CSV、 Archive、Blackhole、Merge、Federated、Example等9种存储引擎;不同存储引擎的各自

存储引擎(Storage Engine)是处理不同类型的表的SQL操作的MySQL部件,也被称为表类型。

MySQL支持多种的存储引擎,比如最新的MySQL 5.6就支持InnoDB、MyISAM、Memory、CSV、 Archive、Blackhole、Merge、Federated、Example等9种存储引擎;不同存储引擎的各自功能、性能和适用场景都各不相同。

5.5.5版本之前的MySQL是使用MyISAM作为默认的存储引擎的;而从5.5.5版本开始,MySQL使用InnoDB作为默认的存储引擎。

查看MySQL支持的存储引擎:

使用“show engines;”SQL语句可以查询当前MySQL支持的存储引擎,如下是在RHEL中的MySQL 5.1.61中的信息:

mysql> show engines;

+------------+---------+------------------------------------------------------------+--------------+------+------------+

| Engine | Support | Comment | Transactions | XA | Savepoints |

+------------+---------+------------------------------------------------------------+--------------+------+------------+

| MRG_MYISAM | YES | Collection of identical MyISAM tables | NO | NO | NO |

| CSV | YES | CSV storage engine | NO | NO | NO |

| MyISAM | DEFAULT | Default engine as of MySQL 3.23 with great performance | NO | NO | NO |

| InnoDB | YES | Supports transactions, row-level locking, and foreign keys | YES | YES | YES |

| MEMORY | YES | Hash based, stored in memory, useful for temporary tables | NO | NO | NO |

+------------+---------+------------------------------------------------------------+--------------+------+------------+

5 rows in set (0.00 sec)

其中Support字段为DEFAULT的引擎是默认的存储引擎。

查看数据库中各个表使用的存储引擎:

mysql> SHOW TABLE STATUS FROM my-db-name;

指定存储引擎(配置):

1. 在mysql配置文件(/etc/my.conf)中指定默认引擎,如用“default-storage-engine=innodb”设置就指定了InnoDB为默认的存储引擎。

2. 在启动mysqld的命令行时添加“–default-storage-engine=innodb”或“–default-table-type=myisam”这样的参数(PS:对于RHEL系统中mysqld服务,可以修改/etc/init.d/mysqld文件中的 $exec 这一行).

3. 创建表时指定存储引擎的类型,如: CREATE TABLE mytable (id int, title char(20)) ENGINE=innodb

4. 改变一个表使用的存储引擎,SQL语句为:ALTER TABLE mytable ENGINE=MyISAM

不同存储引擎的区别:

InnoDB是支持事务的,具有ACID(A: atomicity. C: consistency. I:isolation.D: durability.原子性、一致性、隔离性、持久性)特性;InnoDB也是支持外键(foreign key)的,并且支持细粒度的行级别的锁(row-level locking)。

而MyISAM不支持事务、不支持外键(但其访问速度较快),支持表级别的锁(而不是细粒度的行级别锁)。

Memory存储引擎在较老的MySQL中也叫HEAP,是将所有的数据都存放在内存中的,它具有快速读写的优势,一般存放一些不重要的但需要快速查找的数据(如临时表)。

如下表格来自MySQL官方网站,是一些主流存储引擎的特性比较:

Table 14.1. Storage Engines Feature Summary

Feature

MyISAM

Memory

InnoDB

Archive

NDB

Storage limits

256TB

RAM

64TB

None

384EB

Transactions

No

No

Yes

No

Yes

Locking granularity

Table

Table

Row

Table

Row

MVCC

No

No

Yes

No

No

Geospatial data type support

Yes

No

Yes

Yes

Yes

Geospatial indexing support

Yes

No

No

No

No

B-tree indexes

Yes

Yes

Yes

No

No

T-tree indexes

No

No

No

No

Yes

Hash indexes

No

Yes

No[a]

No

Yes

Full-text search indexes

Yes

No

Yes[b]

No

No

Clustered indexes

No

No

Yes

No

No

Data caches

No

N/A

Yes

No

Yes

Index caches

Yes

N/A

Yes

No

Yes

Compressed data

Yes[c]

No

Yes[d]

Yes

No

Encrypted data[e]

Yes

Yes

Yes

Yes

Yes

Cluster database support

No

No

No

No

Yes

Replication support[f]

Yes

Yes

Yes

Yes

Yes

Foreign key support

No

No

Yes

No

No

Backup / point-in-time recovery[g]

Yes

Yes

Yes

Yes

Yes

Query cache support

Yes

Yes

Yes

Yes

Yes

Update statistics for data dictionary

Yes

Yes

Yes

Yes

Yes

[a]InnoDB utilizes hash indexes internally for its Adaptive Hash Index feature.

[b]InnoDB support for FULLTEXT indexes is available in MySQL 5.6.4 and higher.

[c]Compressed MyISAM tables are supported only when using the compressed row format. Tables using the compressed row format with MyISAM are read only.

[d]Compressed InnoDB tables require the InnoDB Barracuda file format.

[e]Implemented in the server (via encryption functions), rather than in the storage engine.

[f]Implemented in the server, rather than in the storage engine.

[g]Implemented in the server, rather than in the storage engine.

参考资料:

storage engines: http://dev.mysql.com/doc/refman/5.6/en/storage-engines.html

MyISAM: http://dev.mysql.com/doc/refman/5.6/en/myisam-storage-engine.html

InnoDB: http://dev.mysql.com/doc/refman/5.6/en/innodb-storage-engine.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值