简体   繁体   English

什么是MySQL中的InnoDB和MyISAM?

[英]What is InnoDB and MyISAM in MySQL?

什么是MySQL InnoDBMyISAM

InnoDB and MYISAM , are storage engines for MySQL . InnoDBMYISAMMySQL存储引擎。

These two differ on their locking implementation: InnoDB locks the particular row in the table, and MyISAM locks the entire MySQL table. 这两个锁定实现不同: InnoDB锁定表中的特定行, MyISAM锁定整个MySQL表。

You can specify the type by giving MYISAM OR InnoDB while creating a table in DB. 您可以在DB中创建表时通过提供MYISAMInnoDB来指定类型。

Have a look at 看一下

InnoDB and MyISAM InnoDBMyISAM

InnoDB is a storage engine for MySQL, included as standard in all current binaries distributed by MySQL AB. InnoDB是MySQL的存储引擎,作为MySQL AB分发的所有当前二进制文件的标准配置。 Its main enhancement over other storage engines available for use with MySQL is ACID-compliant transaction support 它可以与MySQL一起使用的其他存储引擎的主要增强功能是符合ACID标准的事务支持

MyISAM is the default storage engine for the MySQL relational database management system versions prior to 5.5 1 . MyISAM的是MySQL的关系数据库管理系统版本的默认存储引擎5.5之前的1 It is based on the older ISAM code but has many useful extensions. 它基于较旧的ISAM代码,但有许多有用的扩展。 The major deficiency of MyISAM is the absence of transactions support. MyISAM的主要缺点是缺乏交易支持。 Versions of MySQL 5.5 and greater have switched to the InnoDB engine to ensure referential integrity constraints, and higher concurrency. MySQL 5.5及更高版本的版本已切换到InnoDB引擎,以确保参照完整性约束和更高的并发性。

They are storage engines. 它们是存储引擎。

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

MyISAM: The default MySQL storage engine and the one that is used the most in Web, data warehousing, and other application environments. MyISAM:默认的MySQL存储引擎,也是Web,数据仓库和其他应用程序环境中使用最多的引擎。 MyISAM is supported in all MySQL configurations, and is the default storage engine unless you have configured MySQL to use a different one by default. MyISAM在所有MySQL配置中都受支持,并且是默认存储引擎,除非您已将MySQL配置为默认使用其他MySQL。

InnoDB: A transaction-safe (ACID compliant) storage engine for MySQL that has commit, rollback, and crash-recovery capabilities to protect user data. InnoDB:适用于MySQL的事务安全(ACID兼容)存储引擎,具有提交,回滚和崩溃恢复功能,可保护用户数据。 InnoDB row-level locking (without escalation to coarser granularity locks) and Oracle-style consistent nonlocking reads increase multi-user concurrency and performance. InnoDB行级锁定(没有升级到更粗略的粒度锁)和Oracle风格的一致非锁定读取增加了多用户并发性和性能。 InnoDB stores user data in clustered indexes to reduce I/O for common queries based on primary keys. InnoDB将用户数据存储在聚簇索引中,以减少基于主键的常见查询的I / O. To maintain data integrity, InnoDB also supports FOREIGN KEY referential-integrity constraints. 为了保持数据完整性,InnoDB还支持FOREIGN KEY参照完整性约束。

I wanted to add that having ability to specify a specific storage engine per table is one of the key strengths of MySQL (besides easy of use and good performance with no tweaking). 我想补充一点,有能力为每个表指定一个特定的存储引擎是MySQL的关键优势之一(除了易于使用和良好的性能,没有调整)。 For all operations where transactions are needed, just stick with InnoDB. 对于需要交易的所有操作,只需坚持使用InnoDB即可。 However, MyISAM can really speed things up when transactions are not needed in certain situations - and requires less disk space and RAM compared to InnoDB. 但是,在某些情况下不需要事务时,MyISAM可以真正加快速度 - 与InnoDB相比,需要更少的磁盘空间和RAM。

That said, InnoDB is getting better all the time: 也就是说,InnoDB一直在变得越来越好:

InnoDB 1.1 Performance and Scalability Enhancements InnoDB 1.1性能和可扩展性增强功能

MyISAM does not follow ACID as opposed to InnoDB which follows transactions to maintain integrity of the data. MyISAM不遵循ACID而不是InnoDB,后者遵循事务来维护数据的完整性。

MyISAM supports concurrent inserts: If a table has no free blocks in the middle of the data file, you can INSERT new rows into it at the same time that other threads are reading from the table. MyISAM支持并发插入:如果表在数据文件的中间没有空闲块,则可以在其他线程从表中读取的同时将新行插入其中。 MySqlDoc MySqlDoc

That is why, MyISAM is faster and takes less space. 这就是为什么,MyISAM速度更快,占用空间更少。 For instance, the MySQL MyISAM Storage Engine does not support tranactions. 例如,MySQL MyISAM存储引擎不支持转换。 constraints of MySQL MYISAM There is a bit called concurrent-insert By default, the variable is set to 1 and concurrent inserts are handled as just described. MySQL MYISAM的约束有一种叫做concurrent-insert默认情况下,变量设置为1,并且如前所述处理并发插入。 If it is set to 0, concurrent inserts are disabled. 如果设置为0,则禁用并发插入。 If it is set to 2, concurrent inserts at the end of the table are permitted even for tables that have deleted rows. 如果设置为2,则即使对于已删除行的表,也允许在表末尾进行并发插入。 An INSERT statement can be executed to add rows to the end of the table with select at same time if there are no holes/deleted rows in middle of table (at time of concurrent insert). 如果表中间没有漏洞/删除的行(在并发插入时),则可以执行INSERT语句以将行添加到表的末尾并同时选择。

The default isolation level og mysql InnoDB is "Read Repeatable". 默认隔离级别og mysql InnoDB是“Read Repeatable”。 For MyISAM, there is no transaction. 对于MyISAM,没有交易。 InnoDB uses row level locking while MyISAM can only use table level locking that is why InnoDB has crash revovery is better than MyISAM. InnoDB使用行级锁定,而MyISAM只能使用表级锁定,这就是为什么InnoDB崩溃重建比MyISAM更好。 One has to manually acquire the table level lock in MyISAM if one wants to avoid the concurrency effects. 如果想要避免并发效应,必须手动获取 MyISAM中的表级锁

InnoDB是默认的NOT myISAM https://dev.mysql.com/doc/refman/5.7/en/innodb-introduction.html“InnoDB是默认的MySQL存储引擎。除非你配置了不同的默认存​​储引擎,否则发布一个没有ENGINE =子句的CREATE TABLE语句创建一个InnoDB表“

When your MySQL server crashes, the data can be recovered much easier from a set of MyISAM tables than from that big InnoDB transaction file. 当您的MySQL服务器崩溃时,从一组MyISAM表中可以比从大型InnoDB事务文件中恢复数据更容易。 Each MyISAM table has a separate file, and if no write operations were being made to this table during the crash - it will be totally unaffected. 每个MyISAM表都有一个单独的文件,如果在崩溃期间没有对该表进行写操作 - 它将完全不受影响。 In case of InnoDB, the entire transaction file of the entire MySQL server has to be re-indexed or whatever it does after a crash. 对于InnoDB,整个MySQL服务器的整个事务文件必须重新编制索引,或者在崩溃后执行任何操作。 That can get quite messy. 这可能会变得非常混乱。

InnoDB is a transactional storage engine of MySQL whereas MyISAM is a non-transactional storage engine. InnoDB是MySQL的事务存储引擎,而MyISAM是非事务性存储引擎。 In other words, InnoDB follows the ACID properties to maintain the integrity of data but MyISAM doesn't follow ACID properties thus failing to maintain the integrity of the data. 换句话说,InnoDB遵循ACID属性来维护数据的完整性,但MyISAM不遵循ACID属性,因此无法保持数据的完整性。

In an InnoDB (transactional) table, the transactional changes can be easily undone if a rollback is required. 在InnoDB(事务性)表中,如果需要回滚,则可以轻松撤消事务更改。 But changes made to a MyISAM (non-transactional) table cannot be undone when rolling back a transaction is required. 但是,在需要回滚事务时,无法撤消对MyISAM(非事务性)表所做的更改。

For example, you want to transfer money from your checking account to saving account. 例如,您希望将支票帐户中的资金转帐到储蓄帐户。 This is done by a transaction which includes 5 queries. 这是由包含5个查询的事务完成的。

1 START TRANSACTION;
2 SELECT balance FROM checking WHERE customer_id = 10233276;
3 UPDATE checking SET balance = balance - 200.00 WHERE customer_id = 10233276;
4 UPDATE savings SET balance = balance + 200.00 WHERE customer_id = 10233276;
5 COMMIT;

Suppose, the process crashes at step 4. If a InnoDB table was used here, a rollback would undo the changes and you are saved from the risk of losing money. 假设,该过程在步骤4崩溃。如果在此使用InnoDB表,则回滚将撤消更改,您可以免于赔钱的风险。 Literally, the table is unaware of any crash as the changes will not be commited to the table unless step 5 is successfully executed. 从字面上看,表格不知道任何崩溃,因为除非成功执行第5步,否则不会将更改提交到表中。

But in the case of a MyISAM table, one cannot undo the transactional changes when a rollback is called or if there is a crash leading to the failure of the transaction. 但是在MyISAM表的情况下,当调用回滚或导致事务失败的崩溃时,无法撤消事务更改。 This means, if the transaction crashed at step 3, money will be deducted from your checking account. 这意味着,如果交易在步骤3中崩溃,将从您的支票账户中扣除资金。 But money wouldnot have been added to your savings account. 但是钱不会被添加到您的储蓄账户中。

Example courtesy: "High Performance MySQL: Optimization, Backups, and Replication" - Book by Arjen Lentz, Derek J. Balling, Jeremy Zawodny, Peter Zaitsev, and Vadim Tkachenko 示例礼貌: “高性能MySQL:优化,备份和复制” - 由Arjen Lentz,Derek J. Balling,Jeremy Zawodny,Peter Zaitsev和Vadim Tkachenko撰写的书

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM