---Advertisement---

Storage Engines in MySQL 8

By DBAStack

Updated on:

---Advertisement---

Introduction

In this article, we will get a detailed overview of Storage Engines in MySQL. As we all know MySQL is an open-source relational database that is very easy to use It is also owned by Oracle. 

You can check the ranking of the databases as well which shows after Oracle, MySQL is the most widely used open-source database in the world. You can also Install the MySQL server on your machine and start practicing it.

What is a storage engine in MySQL?

Storage engines in MySQL are a part that manages a database table’s SQL operations. It helps to retrieve and store the data inside the database. The features and benefits of storage engines vary, therefore it is critical to choose the one that best suits the requirements of your application.

MySQL Engine Types

MySQL supports multiple storage engines, and each one of them is designed in a way to meet different needs. Here comes the main part to explore each storage engine in MySQL.

Command : – show engines;

Default Storage Engine in MySQL

InnoDB is the default storage engine in MySQL, chosen for its robustness, reliability, and performance. Here’s a detailed explanation of why it’s the default and its key features:

1. ACID Compliance

InnoDB is the storage engine that supports all types of transactions.

A) Atomicity: It involves transactions like COMMIT & ROLLBACK.

B) Consistency : It is a mechanism used for Crash Recovery.

C) Isolation : Different isolation levels apply at each transaction level.

D) Durability : The storage engine interacts with underlying hardware to provide the best performance

2. Transactions

InnoDB is a transactional storage engine supporting Commit, Rollback, and Savepoint operations. Transactions help to ensure data integrity, especially in the case of complex operations.

3. Row-Level Locking

It uses Row-level locking instead of table-level locking, It also supports Indexing.

4. Efficient Memory Usage

It maintains its own buffer pool (memory area where the InnoDB cache table and indexed data are stored)

5. Crash Recovery

It has also supported the crash recovery mechanism. At the time of system failure, it uses its transactional logs and checkpoint system to detect the failure and resolve it.

a) FEDERATED Storage Engine is Disabled by default.

b) The Tables that are created with FEDERATED Storage Engine, normally point to a table in another MySQL instance installed on a separate server.

c) In Microsoft SQL Server this mechanism is called Linked Server whereas in Oracle it is called Database link.

d) Both tables should have the same name and definition i.e. Requester and Target tables.

e) The table in the requester acts like a view.

Create table employees (Employee_id int, Employee_salary int) ENGINE=FEDERATED CONNECTION = ‘mysql://db_user@target-server:3306/employees/employees’;

a) In MEMORY storage engine Table data will be written in Memory only instead of the physical files.

a) No Transaction support.

b) No Referential Integrity support – No Foreign Key.

c) No TEXT data type support – No BLOB column.

CREATE TABLE continents ( id int NOT NULL, name VARCHAR(25) NOT NULL) ENGINE=MEMORY;

a) BLACKHOLE Storage engine acts like a Black hole, which means whatever the data goes in this engine will never come back. It will disappear.

b) You can store as much data as you want, when you retrieve it, it returns an empty result set.

a) It does not support transaction mechanisms.

CREATE TABLE continents ( id int NOT NULL, name VARCHAR(25) NOT NULL) ENGINE=BLACKHOLE;

a) CSV storage engine stores tables in text files using comma-separated values format.

b) MySQL creates a .csv file in the $DATA_DIR – plain text file.

c) CSV format can be read, and written by spreadsheet applications like Excel.

Note: – Below is the command to find out the $DATA_DIR path.

Storage engines in MySQL

a) It does not support transaction mechanisms.

b) CSV files are not indexed.

CREATE TABLE continents ( id int NOT NULL, name VARCHAR(25) NOT NULL) ENGINE=CSV;

a) MyISAM = My + ISAM = Indexed Sequential Access Method.

b) Indexing algorithm developed by IBM that allows retrieving information from large sets of data in a fast way.

c) MyISAM was the default storage engine up until MySQL 5.5 – around 2009-2010.

d) Good speed advantages especially useful in Data warehouse scenarios.

e) it is replaced by InnoDB.

a) It does not support transactions – ACID Model

Note: – MyISAM ENGINE is used in Data Warehouse databases where there are a lot of reads of the records.

CREATE TABLE continents ( id int NOT NULL, name VARCHAR(25) NOT NULL) ENGINE=MYISAM;

a) ARCHIVE Storage Engine Produces special-purpose tables that store large amounts of un-indexed data in a very small footprint.

b) Creates .ARZ files with the same name as the table name.

c) ARZ files are binary data files and are called MySQL Archive Storage Engine Data Files.

d) Uses gzip to compress rows.

a) No DELETE or UPDATE operation.

b) No Partitioning.

CREATE TABLE continents ( id int NOT NULL, name VARCHAR(25) NOT NULL) ENGINE=ARCHIVE;

a) It is a general-purpose storage engine that balances high reliability and high
performance.

b) In MySQL 8, It is a default storage engine.

c) Its DML operations follow the ACID model.

d) Transactions support commit, rollback, and crash-recovery to protect data.

e) It supports the Row-Level Locking function.

f) InnoDB tables arrange data on disk to optimize queries based on PK.

g) Each InnoDB table has a primary key index, clustered index, and arranged data.

h) Data Integrity supports FK constraints.

CREATE TABLE continents ( id int NOT NULL, name VARCHAR(25) NOT NULL) ENGINE=InnoDB;

CREATE TABLE continents ( id int NOT NULL, name VARCHAR(25) NOT NULL);

Note: – We can use the above commands to create a table in the InnoDB engine, if we cannot give the engine value then also it will be created under the InnonDb engine as it is set by default.

Conclusion

A storage engine dictates the way MySQL handles the storage, retrieval, and processing of data within tables. InnoDB serves as the default storage engine in MySQL.

FAQ’s

How many types of engines are in MySQL?

There are a total of 11 engines are there and every engine has its role. However, we need to choose the engine accordingly as per our use. InnoDB is the default engine from MySQL version 8, before that it was MyISAM.

You can use the below command to check the details of Storage Engines.

Command : show engines;

How to change storage engine in MySQL?

You can use the below steps If you want to change the storage engine of a table in MySQL.

a) You can check the present storage engine of a table by using the below command.

select table_name, engine from information_schema.tables where table_name=’&TABLE_NAME’;

b) Now you can use the below command to change the Storage engine of a Table.

Command : ALTER TABLE (&TABLE_NAME) ENGINE = ‘ENGINE_NAME’;

eg. ALTER TABLE continents ENGINE = ‘InnoDB’;

What is the difference between InnoDB and MyISAM?

Below are the differences between InnoDB and MyIASM.

a) Transactions : It fully supports ACID-compliant transactions in InnoDB whereas it is not supported in MyIASM.

b) Foreign Key Constraints : It Supports foreign key relationships for referential integrity In InnoDB whereas it is not supported in MyIASM.

c) Locking Mechanism : InnoDB uses row-level locking for better concurrency whereas MyISAM Uses table-level locking.

d) Crash Recovery : Robust crash recovery with automatic data recovery in the InnoDB engine whereas Limited crash recovery, may lose data in MyISAM.

e) Replication : InnoDB Supports row-based and statement-based replication whereas MyIASM Supports only statement-based replication.

f) Use Case : InnoDB is Best for transactional systems like e-commerce, and banking apps whereas MyIASM is Ideal for read-heavy applications like data warehouses.

DBAStack

I have experience in database technology for more than 8 years. I hope with the help of this blog I will share knowledge and real-world experience with you all. You all can join me and together we will explore the world of database technology!

---Advertisement---

Related Post

Example of Storage Engine in MySQL 8

Installation of MySQL Server

Leave a Comment