MySQL Storage engine Summary

Source: Internet
Author: User
Tags app service table definition

MySQL storage engine total results frozen want font: [Increase decrease] Type: Reproduced this article mainly introduces the MySQL storage engine summary, this article explains what is storage engine, MyISAM, InnoDB, memory, merge and other content, the need for friends can refer to the next

Objective

In the database is a sheet of inextricably linked tables, so the table design is good or bad, will directly affect the entire database. While designing the table, we will focus on one issue and what storage engine to use. Wait a minute, storage engine? What is a storage engine?

What is a storage engine?

Relational database tables are data structures for storing and organizing information, and you can interpret tables as tables of rows and columns, similar to the form of spreadsheets in Excel. Some tables are simple, some tables are complex, some tables do not have to store any long-term data, some tables are read very fast, but when inserting data is very poor, and we in the actual development process, we may need a variety of tables, different tables, it means the storage of different types of data, data processing will also exist differences, then. For MySQL, it offers many types of storage engines, and we can take advantage of MySQL's powerful capabilities by choosing different storage engines based on the need for data processing. This blog post will summarize and analyze the features of each engine, as well as the application scenarios, and will not be entangled in deeper things. My Learning method is to learn to use, know how to use, and then to understand how it can be used. The following is a brief introduction to the MySQL-supported storage engine.

MyISAM

In the MySQL client, use the following command to view the MySQL-supported engine.

Copy CodeThe code is as follows:
Show engines;
The MyISAM table is independent of the operating system, which means that it can be easily ported from a Windows Server to a Linux server, and every time we build a table for a MyISAM engine, three files are created on the local disk, which is indicated by the file name. For example, if I build a tb_demo table for the MyISAM engine, the following three files will be generated:

1.TB_DEMO.FRM, storage table definition;
2.tb_demo. MYD, storing data;
3.tb_demo. MYI, stores the index.

The MyISAM table cannot handle transactions, which means that there is a table for transaction processing requirements and cannot use the MyISAM storage engine. The MyISAM storage engine is ideal for use in the following situations:

1. Select the intensive table. The MyISAM storage engine is very fast in filtering large amounts of data, which is its most prominent advantage.
2. Insert intensive tables. The concurrent Insert feature of MyISAM allows data to be selected and inserted at the same time. For example, the MyISAM storage engine is ideal for managing mail or Web server log data.

InnoDB

InnoDB is a robust transactional storage engine that has been used by many Internet companies to provide a powerful solution for users to operate very large data stores. MySQL version 5.6.13 is installed on my computer, and InnoDB is the default storage engine. InnoDB also introduces row-level locking and foreign key constraints, which are ideal for use with InnoDB in the following situations:

1. Update the dense table. The InnoDB storage engine is ideal for handling multiple concurrent update requests.
2. Transactions. The InnoDB storage engine is a standard MySQL storage engine that supports transactions.
3. Automatic disaster recovery. Unlike other storage engines, the InnoDB table can automatically recover from a disaster.
4. Foreign KEY constraints. MySQL supports the foreign key storage engine only InnoDB.
5. Support automatic increment of column auto_increment attribute.

In general, InnoDB is a good choice if transaction support is required and there is a high frequency of concurrent reads.

MEMORY

The starting point for using the MySQL memory storage engine is speed. To get the fastest response time, the logical storage medium used is system memory. Although storing table data in memory does provide high performance, all memory data will be lost when the mysqld daemon crashes. The speed of the acquisition also brings some drawbacks. It requires that the data stored in the Memory data table use a constant length format, which means that a variable length data type such as BLOB and text cannot be used, and varchar is a variable-length type, but because it is a fixed-length char type within MySQL, So it can be used.

Memory storage engines are typically used in the following situations:

1. The target data is small and is accessed very frequently. Storing the data in memory, so it will cause the use of memory, can be controlled by the parameter max_heap_table_size the memory table size, set this parameter, you can limit the memory table maximum size.

2. If the data is temporary and required to be immediately available, it can be stored in the memory table.

3. Data stored in the memory table, if suddenly lost, will not have a substantial negative impact on the app service.

Memory supports both hash index and B-Tree index. The B-Tree index is better than the hash index, you can use partial queries and wildcard queries, or you can use operators such as <, >, and >= to facilitate data mining. Hash indexes are very fast for equality comparisons, but are much slower for range comparison, so the hash index values are suitable for use in operators of = and <>, not in the < or > operators, nor in the ORDER BY clause.

You can use the Using clause to specify the version to use when the table is created. For example:

Copy CodeThe code is as follows:
CREATE TABLE Users
(
ID smallint unsigned NOT NULL auto_increment,
Username varchar () NOT NULL,
PWD varchar (NOT NULL),
Index using hash (username),
Primary KEY (ID)
) Engine=memory;

The code above creates a table that uses a hash hash index on the username field. The following code creates a table that uses the Btree index.

Copy CodeThe code is as follows:
CREATE TABLE Users
(
ID smallint unsigned NOT NULL auto_increment,
Username varchar () NOT NULL,
PWD varchar (NOT NULL),
Index using Btree (username),
Primary KEY (ID)
) Engine=memory;

MERGE

The merge storage engine is a combination of a set of MyISAM tables that must be identical in structure, although their use is not as prominent as other engines, but is useful in some cases. To be blunt, the merge table is just a few aggregators of the same MyISAM table, and there is no data in the merge table, and the merge type table can be queried, updated, deleted, and actually operated on the internal MyISAM table. The usage scenario for the merge storage engine.

For server logs, the most common storage strategy is to divide the data into tables, each associated with a specific time-end. For example, you can use 12 identical tables to store server log data, each named by the name of each month. When it is necessary to generate a report based on data from all 12 log tables, this means that multiple table queries need to be written and updated to reflect the information in those tables. Instead of writing these queries that may have errors, instead of merging the tables with a single query and then deleting the merge table without affecting the original data, deleting the merge table simply removes the definition of the merge table and has no effect on the internal table.

ARCHIVE

Archive is archived, many of the advanced features are no longer supported after archiving, supporting only the most basic insert and query functions. Prior to MySQL version 5.5, archive did not support indexing, but it began to support indexing in MySQL 5.5. Archive has a good compression mechanism, which uses the Zlib compression library, which is compressed in real time when the record is requested, so it is often used as a repository.

Some problems with the storage engine

1. How can I see which storage engines are available for the server?
To determine which storage engines your MySQL server can use, execute the following command:

Copy CodeThe code is as follows:
Show engines;
This command will take care of it.

2. How do I choose the right storage engine?
(1) Selection criteria can be divided into:
(2) Whether support services are required;
(3) Whether it is necessary to use hot standby;
(4) Crash recovery: can accept crashes;
(5) Whether foreign key support is required;
Then, according to the standard, select the corresponding storage engine.

Summarize

This article summarizes several more commonly used storage engine, for the actual work, needs according to the concrete situation, the actual project instance carries on the application, is the best study method.

MySQL Storage engine Summary

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.