Differences: 1. InnoDB supports transactions, but MyISAM does not support it; 2. InnoDB supports foreign keys, but MyISAM does not support it; 3. InnoDB is a clustered index, while MyISAM is a non-clustered index; 4. Innodb does not support full-text indexes , while MyISAM supports full-text index; 5. InnoDB supports table and row-level locks, while MyISAM supports table-level locks; 6. InnoDB tables must have unique indexes, but Myisam does not need them; 7. The storage files are different.
The operating environment of this tutorial: windows7 system, mysql8 version, Dell G3 computer.
InnoDB: MySQL’s default transactional engine is also the most important and widely used storage engine. It is designed to have a large number of short-term transactions. In most cases, short-term transactions are submitted normally and are rarely rolled back. InnoDB's performance and automatic crash recovery features make it popular for non-transactional storage needs. Unless there is a very special reason to use another storage engine, the InnoDB engine should be given priority.
MyISAM: In MySQL 5.1 and earlier versions, MyISAM is the default engine. MyISAM provides a large number of features, including full-text indexing, compression, spatial functions (GIS), etc., but MyISAM does not support transactions and row-level locks, and an undoubted flaw is that it cannot be safely recovered after a crash.
The difference between MyISAM and InnoDB in mysql:
1. InnoDB supports transactions, but MyISAM does not. For every SQL statement in InnoDB By default, languages are encapsulated into transactions and automatically submitted, which will affect the speed, so it is best to put multiple SQL languages between begin and commit to form a transaction;
2. InnoDB Supports foreign keys, while MyISAM does not. Converting an InnoDB table containing foreign keys to MYISAM will fail;
3. InnoDB is a clustered index, using B Tree as the index structure, and the data file is tied to the (primary key) index. Together (the table data file itself is an index structure organized by B Tree), there must be a primary key, and indexing through the primary key is very efficient. However, the auxiliary index requires two queries, first to query the primary key, and then to query the data through the primary key. Therefore, the primary key should not be too large, because if the primary key is too large, other indexes will also be large.
MyISAM is a non-clustered index and also uses B Tree as the index structure. The index and data files are separated, and the index saves the pointer of the data file. Primary key indexes and secondary indexes are independent.
That is to say: the leaf nodes of InnoDB's B-tree primary key index are data files, and the leaf nodes of the auxiliary index are the values of the primary key; while the leaf nodes of MyISAM's B-tree primary key index and auxiliary index are both data files. address pointer.
4. InnoDB does not save the specific number of rows in the table, and the entire table is required when executing select count(*) from table scanning. MyISAM uses a variable to save the number of rows in the entire table. When executing the above statement, you only need to read the variable, which is very fast (note that no WHERE conditions can be added);
So why? What if InnoDB doesn't have this variable?
Because of the transaction characteristics of InnoDB, the number of rows in the same time table is different for different transactions, so the count statistics will calculate the number of rows that can be counted for the current transaction, not Store the total number of rows for quick query. InnoDB will try to traverse the smallest possible index unless the optimizer prompts to use another index. If the secondary index does not exist, InnoDB will also try to traverse other clustered indexes.
If the index is not completely in the buffer maintained by InnoDB (Buffer Pool), the count operation will be more time-consuming. You can create a table that records the total number of rows and let your program update the corresponding data during INSERT/DELETE. Like the problem mentioned above, this solution is not very useful if there are multiple transactions at this time. If the approximate row value is enough to meet your needs, you can try SHOW TABLE STATUS
5. Innodb does not support full-text indexing, but MyISAM supports full-text indexing. In terms of query efficiency in the field of full-text indexing MyISAM is faster and faster; PS: InnoDB after 5.7 supports full-text indexing
6. MyISAM tables can be compressed for query operations
7. InnoDB supports table and row (default) level locks, while MyISAM supports table-level locks
InnoDB’s row lock is implemented on the index, rather than locking on the physical row record. The subtext is that if the access does not hit the index and the row lock cannot be used, it will degenerate into a table lock.
For example:
t_user(uid, uname, age, sex) innodb; uid PK 无其他索引 update t_user set age=10 where uid=1; 命中索引,行锁。 update t_user set age=10 where uid != 1; 未命中索引,表锁。 update t_user set age=10 where name='chackca'; 无索引,表锁。
8. The InnoDB table must have a unique index (such as a primary key) (if the user does not specify it, he or she will find/produce a hidden column Row_id to serve as the default primary key). And Myisam can not have it
9. Innodb storage files include frm and ibd, while Myisam is frm, MYD, MYI
Innodb: frm is Table definition file, ibd is the data file
Myisam: frm is the table definition file, myd is the data file, myi is the index file
##How to choose:
1. Do you want to support transactions? If so, please choose innodb. If not, you can consider MyISAM;
2. If most of the tables are only read queries, you can consider MyISAM. If there are both reads and writes, please use InnoDB.
3. After the system crashes, it will be more difficult for MyISAM to recover, is it acceptable?
4. Innodb has been released since MySQL 5.5 version Becoming the default engine of Mysql (previously MyISAM) shows that its advantages are obvious to all. If you don’t know what to use, then use InnoDB, at least it will not be bad.
Why does InnoDB recommend using auto-incrementing ID as the primary key?
Answer: Auto-incrementing ID can ensure that the B index is expanded from the right every time it is inserted, which can avoid B-tree and frequent merging and splitting (compared to using UUID). If you use string primary keys and random primary keys, data will be inserted randomly and the efficiency will be poor.
The 4 major features of innodb engine
## Insert buffer, double write , adaptive hash index (ahi), read ahead (read ahead)[Related recommendations:
mysql video tutorialThe above is the detailed content of What is the difference between MyISAM and InnoDB in mysql. For more information, please follow other related articles on the PHP Chinese website!

MySQL uses a GPL license. 1) The GPL license allows the free use, modification and distribution of MySQL, but the modified distribution must comply with GPL. 2) Commercial licenses can avoid public modifications and are suitable for commercial applications that require confidentiality.

The situations when choosing InnoDB instead of MyISAM include: 1) transaction support, 2) high concurrency environment, 3) high data consistency; conversely, the situation when choosing MyISAM includes: 1) mainly read operations, 2) no transaction support is required. InnoDB is suitable for applications that require high data consistency and transaction processing, such as e-commerce platforms, while MyISAM is suitable for read-intensive and transaction-free applications such as blog systems.

In MySQL, the function of foreign keys is to establish the relationship between tables and ensure the consistency and integrity of the data. Foreign keys maintain the effectiveness of data through reference integrity checks and cascading operations. Pay attention to performance optimization and avoid common errors when using them.

There are four main index types in MySQL: B-Tree index, hash index, full-text index and spatial index. 1.B-Tree index is suitable for range query, sorting and grouping, and is suitable for creation on the name column of the employees table. 2. Hash index is suitable for equivalent queries and is suitable for creation on the id column of the hash_table table of the MEMORY storage engine. 3. Full text index is used for text search, suitable for creation on the content column of the articles table. 4. Spatial index is used for geospatial query, suitable for creation on geom columns of locations table.

TocreateanindexinMySQL,usetheCREATEINDEXstatement.1)Forasinglecolumn,use"CREATEINDEXidx_lastnameONemployees(lastname);"2)Foracompositeindex,use"CREATEINDEXidx_nameONemployees(lastname,firstname);"3)Forauniqueindex,use"CREATEU

The main difference between MySQL and SQLite is the design concept and usage scenarios: 1. MySQL is suitable for large applications and enterprise-level solutions, supporting high performance and high concurrency; 2. SQLite is suitable for mobile applications and desktop software, lightweight and easy to embed.

Indexes in MySQL are an ordered structure of one or more columns in a database table, used to speed up data retrieval. 1) Indexes improve query speed by reducing the amount of scanned data. 2) B-Tree index uses a balanced tree structure, which is suitable for range query and sorting. 3) Use CREATEINDEX statements to create indexes, such as CREATEINDEXidx_customer_idONorders(customer_id). 4) Composite indexes can optimize multi-column queries, such as CREATEINDEXidx_customer_orderONorders(customer_id,order_date). 5) Use EXPLAIN to analyze query plans and avoid

Using transactions in MySQL ensures data consistency. 1) Start the transaction through STARTTRANSACTION, and then execute SQL operations and submit it with COMMIT or ROLLBACK. 2) Use SAVEPOINT to set a save point to allow partial rollback. 3) Performance optimization suggestions include shortening transaction time, avoiding large-scale queries and using isolation levels reasonably.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Dreamweaver CS6
Visual web development tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Linux new version
SublimeText3 Linux latest version

SublimeText3 Mac version
God-level code editing software (SublimeText3)
