What is the difference between the database engine InnoDB and MyISAM
The general difference is that the MyISAM type does not support advanced processing such as transaction processing, and InnoDB type support. MyISAM types of tables emphasize performance, which performs more efficiently than InnoDB types, but does not support transactions, while InnoDB provides transactional support and advanced database functionality such as foreign keys.
The difference between specific implementations:
InnoDB does not support indexes of fulltext types
The exact number of rows in a table is not saved in InnoDB, that is, when querying SQL is executed, INNODB scans the entire table to calculate how many rows, and MyISAM simply reads the saved rows, but when the where condition is included, the operation of the two tables is the same
For fields of type auto_increment, InnoDB must contain only the index of the field, but in the MyISAM table, you can establish a federated index with other fields
When you execute a delete SQL, InnoDB does not reestablish the table, but deletes a row of rows
The LOAD TABLE from master operation has no effect on InnoDB. The workaround is to change the InnoDB table to a MyISAM table, import the data, and then change it to a InnoDB table, but not for tables that use additional InnoDB features (such as foreign keys)
The difference in composition:
Each myisam is stored on a disk divided into three files. The first file name starts with the name of the table, and the extension indicates the file type
. frm file storage table definition
. myd files as data files
. Myi files as index files
Disk-based resources are data files for the InnoDB tablespace and its log files, and the InnoDB table size is limited only by the size of the operating system files, typically 2G
How to select the Database engine
Whether the business needs to support things, if you need to choose InnoDB, if you do not need to consider MyISAM
If the vast majority of the tables are simply query operations, consider MyISAM, and if read and write operations are frequent, use InnoDB
Need to consider a system crash, MyISAM recovery is more difficult, can accept
MySQL5.5 version started InnoDB has become the default engine for MySQL (previously MyISAM)
MySQL Field width
The display width of the integer value is specified in parentheses following the MySQL type keyword (for example, INT (11)). The optional display width specifies that the width is filled from the left when the value that is less than the specified width of the column is displayed. The display width does not limit the range of values that can be saved within the column, nor does it limit the display of values that exceed the specified width of the column. so int (1) and int (11) are no different by default!!!
When combined with optional extended attribute Zerofill, the default supplemental space is replaced with 0. For example, for a column declared as int (5) Zerofill, the value 4 is retrieved as 00004. Note that if you save a value that exceeds the display width in an integer column, you will encounter problems when MySQL generates temporary tables for complex joins, because in these cases MySQL believes that the data fits the original column width.
All integer types can have an optional (non-standard) attribute of unsigned. Unsigned values can be used when you want to allow only non-negative numbers in a column and the column requires a large upper range of values. If you set the Zerofill extended Properties test, the default is unsigned (UNSIGNED)
So the characters in parentheses after int (1) and int (11) represent the width of the display, the display width of the integer column and the number of characters required by MySQL to display the value of the columns, and the size of the storage space required by the integer, the data limit of the type of int can be stored or 2147483647 ( Signed) and 4294967295 (unsigned). In fact, when we choose the type of int, whether int (1) or int (11), it stores the length of 4 bytes in the database.
Int (m) Zerofill, plus Zerofill after M to show a difference, such as int (3) Zerofill, you insert into the database is 10, the actual insert is 010, that is, add a 0 in front. if int (3) and int (10) Without Zerofill, they are no different. M is not used to limit the range of values stored in an int column. The maximum and minimum values of int (M) are related to unsigned.
In general, the main difference between the two types is that InnoDB supports object handling and foreign key and row level locks. And MyISAM does not support it. So MyISAM tend to be considered only for use in small projects, and MyISAM is definitely the first choice for convenience and high scalability. The reasons are as follows:
1, most of the projects on the platform are read and write less projects, and MyISAM reading performance is stronger than InnoDB.
2, MyISAM index and data are separate, and the index is compressed, the memory usage of the corresponding improved a lot. Can load more indexes, and InnoDB is the index and the data is tightly bound, do not use compression which will cause innodb than MyISAM volume is large.
3, often 1, 2 months will occur application developers accidentally update a table where the scope of the wrong, resulting in this table can not be normal use, this time the superiority of the MyISAM is reflected, casually from the day of the copy of the compressed package out of the corresponding table file, casually put into a database directory, Then dump into SQL and then back to the main library, and the corresponding binlog complement. If it's InnoDB, I'm afraid it can't be so fast, don't tell me to let InnoDB regularly back up with an export xxx.sql mechanism, because the minimum amount of data for a database instance is roughly dozens of g in size.
4, from the application logic of contact, select COUNT (*) and order BY is the most frequent, probably can account for the entire SQL total statement of more than 60% of the operation, and this operation InnoDB actually will lock the table, many people think InnoDB is a row-level lock, That's just where the primary key is valid, and the non-primary key will lock the full table.
5, there is often a lot of application departments need me to give them regular data on some tables, MyISAM words are very convenient, as long as they correspond to the list of the frm. myd,myi files, let them in the corresponding version of the database to start the line, and InnoDB need to export xxx.sql, because the light to other people's files, by the dictionary data file, the other side is not available.
6, if and myisam than insert write operation, InnoDB also not up to MyISAM write performance, if is for index-based update operation, although MyISAM may be inferior innodb, but so high concurrency of write, from the library can chase is also a problem, It might as well be solved by a multi-instance sub-Library table architecture.
7, if it is used MyISAM, the merge engine can greatly speed up the development of the application department, they just do some select count (*) operation on this merge table, it is very suitable for a large project total of about hundreds of millions of rows of a type (such as log, survey statistics) business table.
8, of course, InnoDB is not absolutely not used, the project with the business of InnoDB. In addition, someone might say that you myisam not be able to write too much, but you can make up for it through architecture.