What is the difference between MyISAM and InnoDB in mysql
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!

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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

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

Hot Topics



MySQL is an open source relational database management system. 1) Create database and tables: Use the CREATEDATABASE and CREATETABLE commands. 2) Basic operations: INSERT, UPDATE, DELETE and SELECT. 3) Advanced operations: JOIN, subquery and transaction processing. 4) Debugging skills: Check syntax, data type and permissions. 5) Optimization suggestions: Use indexes, avoid SELECT* and use transactions.

You can open phpMyAdmin through the following steps: 1. Log in to the website control panel; 2. Find and click the phpMyAdmin icon; 3. Enter MySQL credentials; 4. Click "Login".

MySQL is an open source relational database management system, mainly used to store and retrieve data quickly and reliably. Its working principle includes client requests, query resolution, execution of queries and return results. Examples of usage include creating tables, inserting and querying data, and advanced features such as JOIN operations. Common errors involve SQL syntax, data types, and permissions, and optimization suggestions include the use of indexes, optimized queries, and partitioning of tables.

MySQL is chosen for its performance, reliability, ease of use, and community support. 1.MySQL provides efficient data storage and retrieval functions, supporting multiple data types and advanced query operations. 2. Adopt client-server architecture and multiple storage engines to support transaction and query optimization. 3. Easy to use, supports a variety of operating systems and programming languages. 4. Have strong community support and provide rich resources and solutions.

Redis uses a single threaded architecture to provide high performance, simplicity, and consistency. It utilizes I/O multiplexing, event loops, non-blocking I/O, and shared memory to improve concurrency, but with limitations of concurrency limitations, single point of failure, and unsuitable for write-intensive workloads.

MySQL and SQL are essential skills for developers. 1.MySQL is an open source relational database management system, and SQL is the standard language used to manage and operate databases. 2.MySQL supports multiple storage engines through efficient data storage and retrieval functions, and SQL completes complex data operations through simple statements. 3. Examples of usage include basic queries and advanced queries, such as filtering and sorting by condition. 4. Common errors include syntax errors and performance issues, which can be optimized by checking SQL statements and using EXPLAIN commands. 5. Performance optimization techniques include using indexes, avoiding full table scanning, optimizing JOIN operations and improving code readability.

MySQL's position in databases and programming is very important. It is an open source relational database management system that is widely used in various application scenarios. 1) MySQL provides efficient data storage, organization and retrieval functions, supporting Web, mobile and enterprise-level systems. 2) It uses a client-server architecture, supports multiple storage engines and index optimization. 3) Basic usages include creating tables and inserting data, and advanced usages involve multi-table JOINs and complex queries. 4) Frequently asked questions such as SQL syntax errors and performance issues can be debugged through the EXPLAIN command and slow query log. 5) Performance optimization methods include rational use of indexes, optimized query and use of caches. Best practices include using transactions and PreparedStatemen

Building an SQL database involves 10 steps: selecting DBMS; installing DBMS; creating a database; creating a table; inserting data; retrieving data; updating data; deleting data; managing users; backing up the database.
