MySQL Table Types/Storage Engines
MySQL table types/storage engines are essential features that can be used effectively for maximizing the database's performance. It handles create, read, and update operations for storing and managing the information in a database. In this tutorial, we are going to understand various storage engines or table types used in MySQL.
The following are various table types/storage engines supports in MySQL:
We can use the below query that determines which table types/storage engines our MySQL server supports.
The Support column value indicates whether an engine can be used or not in the current server. A value of YES, NO, or DEFAULT shows that table type is available, not available, and available & currently set as the default table type/storage engine.
It is essential to understand each table type's features in MySQL that enable us to decide the most appropriate among them for our table that maximizes the performance of our databases. Each table type in MySQL has its own advantages and disadvantages. Let us learn each table type/storage engine and its advantages and disadvantages for choosing which one to use among them.
It is abbreviated as Indexed Sequential Access Method. This table type/storage engine has been deprecated and removed from MySQL version 5.x. MyISAM now replaces the functionalities of this table. The size of an ISAM table is 4 GB, which requires expensive hardware. It is not portable.
It is an extension of the ISAM storage engine. The MyISAM table types are optimized for compression and speed and can be easily portable between system to system. Before version 5.5, if we do not specify the table type during table creation, it was the default storage engine. From version 5.x, InnoDB is used as the default table type/storage engine.
The MyISAM table size is dependent on the OS and can be up to 256 TB. It can be compressed into read-only tables that save spaces in memory. MyISAM table type can store 64 keys per table and contains 1024 bytes maximum key length. The MyISAM tables work very fast, but they are not transaction-safe.
Advantages of MyISAM
Disadvantages of MyISAM
The InnoDB tables in MySQL fully support transaction-safe storage engine with ACID-compliant. It is the first table type that supports foreign keys. The InnoDB tables also provide optimal performance. Its size can be up to 64TB. InnoDB tables are also portable between systems to systems similar to MyISAM. InnoDB tables can also be checked and repairs by MySQL whenever necessary.
Advantages of InnoDB
Disadvantages of InnoDB
MERGE table is also known as MRG_MyISAM. This table combines multiple MyISAM tables with a similar structure (identical column and index information with the same order) into a single table. This table uses indexes of the component tables because it does not have its own indexes. When we join multiple tables, it can also be used to speed up the database's performance. We can perform only INSERT, SELECT, DELETE, and UPDATE operations on the MERGE tables. If we use the DROP TABLE query in this storage engine, MySQL only removed the MERGE specification, and the underlying tables cannot be affected.
Advantages of MERGE
Disadvantages of MERGE
The memory table type/storage engine creates tables, which will be stored in our memory. It is also known as HEAP before MySQL version 4.1. This table type is faster than MyISAM because it uses hash indexes that retrieve results faster. We already know that data stored in memory can be crashed due to power issues or hardware failure. Therefore, we can only use this table as temporary work areas or read-only caches for data pulled from other tables. Hence, the memory/heap tables will be lost whenever the MySQL server halts or restarts. The memory/heap table's data life depends on the uptime of the database server.
Advantages of Memory
The main advantage of this table type is its speed, which is very fast. It is because it uses hash indexing that retrieves results faster.
Disadvantages of Memory
It is not a good idea to use the MEMORY storage for the long term because the data would be lost easily as soon as the power failure or hardware crash.
The CSV table type/storage engine stores data in comma-separated values in a file. It provides a convenient way to migrate data into many different software packages, such as spreadsheet software. This table type is not as good as a general database engine; however, it enables us to exchange our data most effectively and easily. In addition, it will scan the whole table during the read operation.
Advantages of CSV
This table type/storage engine is advantageous when we need to export complex data from one application to a CSV file and then import it into another application.
Disadvantages of CSV
The FEDERATED table type/storage engine supports MySQL from version 5.03 that allows access data from a remote MySQL server without using the cluster/replication technology. The federated storage engine located in local storage does not store any data. If we will query data from a federated table stored in local memory, MySQL automatically pulled data from the remote federated tables. It is to note that it's a way for a server, not for a client, for accessing a remote database. It is an effective way to combine data from more than one host or copy data from remote databases into local tables without using the data import and export method.
This table type/storage engine allows us to store a large volume of data in a compressed format to save disk space and cannot be modified. Thus, it is the perfect storage engine to store log data that is no longer in active use, such as the old invoice or sales data. It compresses the data during the insertion and can decompress it using the Zlib library.
Since it stored the information in a compressed format and if we want to read the table, we first need to decompress the information. This process will take time to perform complex searches and retrievals. Therefore, if we have to perform a large number of queries in these tables, it is beneficial to use another table such as MyISAM.
BDB stands for the Berkeley DB engine, which is developed by SleepyCat software. It is similar to InnoDB in the transaction-safe. It is based on the hash storage mechanism that makes the recovery of information very quickly. It supports page-level locking, but the data file is not portable.