MyISAM 和 InnoDB 有什么区别?

2021-11-20 00:00:00 database mysql innodb myisam

我知道之前有人问过这个问题,但大多数时候是针对特定的数据库或表提出的.我无法在此站点上找到描述这两种引擎及其差异的答案,而不考虑某人的特定数据库.

I understand that this question has been asked before, but most of the time it is asked in relation to a specific database or table. I cannot find an answer on this site that describes the two engines and their differences without respect to someones specific database.

我希望将来能够在设计表或数据库方面做出更明智的决定,因此我正在寻找有关两种存储引擎之间差异的综合答案.

I want to be able to make more informed decisions in the future with respect to designing a table or database, so am looking for a comprehensive answer on the differences between the two storage engines.

MyISAM 和 InnoDB,当我试图在两者之间做出决定时我应该寻找什么?

What's the difference between MyISAM and InnoDB, and what should I be looking for when trying to decide between one or the other?

推荐答案

InnoDB 和 MyISAM 之间的主要区别(关于设计表或数据库"你问过)是对参照完整性"的支持;和交易".

The main differences between InnoDB and MyISAM ("with respect to designing a table or database" you asked about) are support for "referential integrity" and "transactions".

如果您需要数据库强制执行外键约束,或者您需要数据库支持事务(即由两个或多个 DML 操作所做的更改作为单个工作单元处理,应用所有更改,或所有更改更改已恢复),那么您将选择 InnoDB 引擎,因为 MyISAM 引擎中没有这些功能.

If you need the database to enforce foreign key constraints, or you need the database to support transactions (i.e. changes made by two or more DML operations handled as single unit of work, with all of the changes either applied, or all the changes reverted) then you would choose the InnoDB engine, since these features are absent from the MyISAM engine.

这是两个最大的区别.另一个很大的区别是并发性.使用 MyISAM,DML 语句将获得表上的排他锁,并且在持有该锁时,其他会话无法对表执行 SELECT 或 DML 操作.

Those are the two biggest differences. Another big difference is concurrency. With MyISAM, a DML statement will obtain an exclusive lock on the table, and while that lock is held, no other session can perform a SELECT or a DML operation on the table.

您询问的这两个特定引擎(InnoDB 和 MyISAM)具有不同的设计目标.MySQL 还有其他存储引擎,有自己的设计目标.

Those two specific engines you asked about (InnoDB and MyISAM) have different design goals. MySQL also has other storage engines, with their own design goals.

因此,在 InnoDB 和 MyISAM 之间进行选择时,第一步是确定您是否需要 InnoDB 提供的功能.如果没有,则可以考虑使用 MyISAM.

So, in choosing between InnoDB and MyISAM, the first step is in determining if you need the features provided by InnoDB. If not, then MyISAM is up for consideration.

对差异进行更详细的讨论是不切实际的(在本论坛中)缺少对问题空间的更详细讨论...应用程序将如何使用数据库、多少表、表大小、事务负载、大量的选择、插入、更新、并发需求、复制特性等.

A more detailed discussion of differences is rather impractical (in this forum) absent a more detailed discussion of the problem space... how the application will use the database, how many tables, size of the tables, the transaction load, volumes of select, insert, updates, concurrency requirements, replication features, etc.

数据库的逻辑设计应该以数据分析和用户需求为中心;使用关系型数据库的选择会晚一些,更晚的会选择MySQL作为关系型数据库管理系统,然后是为每张表选择一个存储引擎.

The logical design of the database should be centered around data analysis and user requirements; the choice to use a relational database would come later, and even later would the choice of MySQL as a relational database management system, and then the selection of a storage engine for each table.

相关文章