SlideShare a Scribd company logo
INDEX:
A. What is storage engine?
B. Choosing the right engine
C. Specifying and altering storage engines
D. How to tell which storage engine a MySQL table uses?
E. Check MySQL engine type for a specific table?
F. Check the Default Storage Engine of MySQL
G. Setting the Storage Engine
H. Check if InnoDB is enabled in MySQL server
I. Important INNODB storage related parameter innodb_file_per_table
(A)What is storage engine?
In MySQL the data’s are stored as files in any one of the types in storage engines.
MySQL supports pluggable storage engines that we can use any types of engine
belongs to your data. There are two types of storage engines in MySQL Transactional
(The data can be modified in engines) and non-transactional (It can only fetch the
data from engines). The default storage engine for MySQL prior to version 5.5 was
MyISAM. For MySQL 5.5 and later, the default storage engine is InnoDB.
Features of MySQL Storage Engines
Choosing the right storage engine is an important strategic decision, which will impact
future development. If you are planning a production database, then things become
more complicated.
A storage engine is a software module that a database management system uses to
create, read, and update data from a database. There are two types of storage
engines in MySQL. Transactional and non-transactional.
MySQL supported the following types of Storage Engine
1. MyISAM
2. InnoDB
3. Merge
4. Memory
5. Blackhole
6. Archive
7. CSV
8. Federated
1. MyISAM
MyISAM is the oldest and original storage engine. It is a fast storage engine.it does
not support transactions. MyISAM provides table level locking. It is used most in web,
data warehousing. If you create a table without representing the storage engine it
take MyISAM engine as default (before MySQL 5.5 version).MySQL databases are
generally store in data directories and MYISAM tables are stored using 3 files.
.frm - Table structure
.MYD - Data file
.MYI - Index file
MyISAM has most flexible auto increment. The tables can be used to set up merge
tables. The table storage format is portable. Maximum no of indexes per table =
64.Maximum no of columns per index = 16.Blob and TEXT columns can be indexed.
Table size is 256TB. It does not provide for foreign key.
2. InnoDB
InnoDB is the most widely used storage engine with transaction supportive InnoDB is
a Transactional safe storage engine. It is an ACID (Atomicity, Consistency, Isolation,
Durability) compliant storage engine. It supports row-level locking, crash recovery and
multi-version concurrency control.i.e it has commits rollback and crash recovery
capability to recover the data. InnoDB provide row level locking to use multi user
concurrency and performance. It supports foreign key. InnoDB creates two log files
namely "ib_logfile0" and "ib_logfile1" and a data file "ibdata1" in the MySQL data
directory where it stores its tables. MySQL creates an auto-extending 10MB data file
in ibdata1 and two 5MB log files in ib_logfile0 andib_logfile1 in the MySQL data
directory. The table definitions are stored in database directory with a .frm extension
whereas the data is stored in the "ibdata1" - tablespace.Minimum table space size is
10MB. And maximum table space size is 64TB.It is the only engine which provides
foreign key referential integrity constraint.
3. Merge
Merge operates on underlying MyISAM tables. Merge tables help manage large
volumes of data more easily. The MERGE engine type allows you to combine a
number of identical tables into a single table. You can then execute queries that
return the results from multiple tables as if they were just one table. Each table
merged must have the same table definition. The MERGE table is particularly effective
if you are logging data directly or indirectly into a MySQL database and create an
individual table per day, week or month and want to be able to produce aggregate
queries from multiple tables. Transaction No Locking level Table. It logically groups a
series of identical MyISAM tables, and references them as one object. Good for data
warehousing environments.
4. Memory
Memory Storage engine creates tables in memory. It is the fastest engine. The
MEMORY storage engine (previously known as the HEAP storage engine) stores all
data in memory; once the MySQL server has been shut down any information stored
in a MEMORY database will have been lost. However, the format of the individual
tables is kept and this enables you to create temporary tables that can be used to
store information for quick access without having to recreate the tables each time the
database server is started. Cannot contain BLOB or TEXT columns. It has table level
locking. It does not support transactions. Memory storage engine is ideal for creating
temporary tables or quick lookups. The data is lost when the database is restarted.
5. Blackhole
It acts as a “black hole” that accepts data but throws it away and does not store it.
BLACKHOLE engine does not actually store any data. Retrievals always return an
empty set. Although you can create tables and indexes, all SQL statements that would
add or update information to the database are executed without actually writing any
data. The database structure is retained, however, and you can create any indexes on
the (non-existent) information that you want. The functionality can be used in
distributed database design where data is automatically replicated, but not stored
locally. This storage engine can be used to perform performance tests or other
testing.
6. Archive
Archive storage engine is optimized for high speed inserting. It is used for storing
large amounts of data without indexes in a very small footprint. It supports only the
INSERT and SELECT statements, but does support most of the MySQL field types. It
compresses data as it is inserted. It does not support truncations. Information stored
in an ARCHIVE storage engine table is compressed and cannot be modified and so
ARCHIVE tables are perfect for storing log data when an archive table is created,
following files are created in the database directory.
.frm-tabledefinition
.ARZ-DATAfile
.ARM - METADATA file
It does NOT support DELETE, REPLACE and UPDATE. It provides row level locking. It is
ideal for storing, retrieving large amounts of seldom referenced historical archived
data.
7. CSV (Comma Separated Value)
CSV stores data in CSV files. It provides great flexibility, because data in this format is
easily integrated into other applications.. It stores data in text files using comma-
separated values format. When a table is created 2 files are created in the database
directory
.frm-tabledefinition
.CSV - data file
It is not an efficient method for storing large volumes of data, or larger data types like
BLOB, although such types are supported. There is also no indexing. However,
because the data is stored in the CSV format it is exceedingly portable.
8. Federated
Federated storage engine offers the ability to separate MySQL servers to create one
logical database from many physical servers. The FEDERATED storage engine (added
in MySQL 5.03) enables you to access data from remote MySQL database (other
databases may be supported in the future) as if it were a local database. In effect, the
MySQL server acts as a proxy to the remote server, using the MySQL client access
library to connect to the remote host, execute queries and then reformat the data
into the localized format. It does not support transactions. Queries on the local server
are automatically executed on the remote (federated) tables. No data is stored on the
local tables. It is good for distributed environments.
(B)Choosing the right engine :
No storage engine is ideal for all circumstances. Some perform best under certain
conditions and perform worse in other situations. There are trade-offs than must be
considered. A more secure solution takes more resources. It might be slower, take
more CPU time and disk space. MySQL is very flexible in the fact that it provides
several different storage engines. Some of them, like the Archive engine, are created
to be used in specific situations. Ironically this also brings a question, which storage
engine to use? Which may not be easily answered?
In some cases, the answer is clear. Whenever we are dealing with some payment
systems, we are obliged to use the most secure solution. We cannot afford to lose
such sensitive data. InnoDB is the way to go. If we want full-text search, than we must
choose MyISAM.
Only InnoDB supports foreign key referential integrity constraint and if we plan to use
this constraint, then the choice is clear. In many situations we must have enough
experience to choose the right engine. The question is further complicated by the
fact, that we can choose different storage engines for different tables.
(C) Specifying and altering storage engines
The storage engine is specified at the time of the table creation.
MySQL> CREATE TABLE Cars (Id INTEGER PRIMARY KEY, Name VARCHAR (50), Cost
INTEGER) ENGINE='MyISAM';
The ENGINE keyword specifies the storage engine used for this particular table.
If we do not specify the storage engine explicitly, then the default storage engine is
used. Prior to MySQL 5.5 the default storage engine was MyISAM. For MySQL 5.5 and
later, the default storage engine is InnoDB.
MySQL> SHOW VARIABLES LIKE 'storage_engine';
The default storage engine can be found in the storage_engine variable.
It is possible to migrate to a different storage engine. Note that migrating a large table
might take a long time. Also we might run into some problems when migrating tables.
Some features might not be supported in both tables.
MySQL> SELECT ENGINE FROM information_schema.TABLES WHERE
TABLE_SCHEMA='mydb'AND TABLE_NAME='Cars';
This SQL statement finds out the storage engine used for a Cars table in mydb
database. We could also use SELECT CREATE TABLE Cars SQL statement.
The information_schema is a table which stores technical information about our
tables.
MySQL> ALTER TABLE Cars ENGINE='MyISAM';
This SQL statement changes the storage engine to MyISAM.
MySQL> SELECT ENGINE FROM information_schema.TABLES
WHERETABLE_SCHEMA='mydb' AND TABLE_NAME='Cars';
| ENGINE |
| MyISAM |
Now the storage engine is MyISAM.
(D)How to tell which storage engine a MySQL table uses :
MySQL supports multiple storage engines (E.g. . . MyISAM, INNODB, etc…)each
With its pros and cons, and each table in a MySQL database can use a different
storage engine.How to work out which table storage engine is used by a MySQL table,
using either a SQL query or using the web browser tool phpMyAdmin.
SQL Query
After digging around in the phpMyAdmin code I worked out they determine the
MySQL table storage engine by querying the INFORMATION_SCHEMA database. This
is a special database which describes information relating to the various databases on
the server. The query the "products" table of the "test" database to see which storage
engine it is using, you would run this SQL query:
SELECT ENGINE FROM information_schema.TABLES WHERE TABLE_SCHEMA=’test’
AND TABLE_NAME=’products’;
The TABLE_SCHEMA is the name of the database, and TABLE_NAME is the table name
you wish to query. The SQL query above will return the storage engine, assuming the
database and table specified exists, and you have sufficient permissions.
If you wanted to see the storage engine for all tables in your database, do this
instead:
SELECT TABLE_NAME, ENGINE FROM information_schema.TABLES WHERE
TABLE_SCHEMA=’test’;
(E) Check MySQL engine type for a specific table?
SHOW TABLE STATUS WHERE NAME=’table_name‘
This will give you (among other things) an engine column, which is what you want.
SELECT TABLE_NAME, ENGINE FROM information_schema.TABLES where
TABLE_SCHEMA = 'database' AND ENGINE IS NOT NULL;
This excludes MySQL views from the list, which don't have an engine
(F) Check the Default Storage Engine of MySQL
1. Login as a rrot user and connect MySQL promt
2. Start the servers
3. Enter the following line into the MySQL prompt and hit Enter:
USE information_schema;
4. Enter the following line into the MySQL prompt and hit Enter:
SELECT * FROM engines;
5. A table with the Storage Engines of MySQL will show up. Inside the Support
column the Default Storage Engine has the value "DEFAULT".
Value Meaning
YES The engine is supported and is active
DEFAULT Like YES, plus this is the default engine
NO The engine is not supported
DISABLED The engine is supported but has been disabled
(http://dev.mysql.com/doc/refman/5.0/en/show-engines.html)
(G) Setting the Storage Engine:
When you create a new table, you can specify which storage engine to use by adding
an ENGINE table option to the CREATE TABLE statement:
CREATE TABLE t (i INT) ENGINE = INNODB;
If you omit the ENGINE option, the default storage engine is used. Normally, this
is MyISAM, but you can change it by using the --default-storage-engine server startup
option, or by setting the default-storage-engine option in the my.cnf configuration
file.
You can set the default storage engine to be used during the current session by
setting the storage_enginevariable:
SET storage_engine=MYISAM;
When MySQL is installed on Windows using the MySQL Configuration Wizard,
the InnoDB or MyISAM storage engine can be selected as the default.
(See Section 2.3.5.5, “MySQL Server Instance Config Wizard: The Database Usage
Dialog”.)
To convert a table from one storage engine to another, use an ALTER
TABLE statement that indicates the new engine:
ALTER TABLE t ENGINE = MYISAM;
(H) Check if innodb is enabled in Mysql server
MySQL database server has the capability to use different database storage engines.
The database storage engine is what actually does the work of storing and retrieving
data from the underlying database tables.
The storage engines work like a modular code which can be plugged into MySQL.
Among the storageengineer’s MyISAM is the one, used most widely and also the
default storage engine for MySQL. However it does lack some high level functionality
which is requirement for any enterprise level database server e.g. it does not have
proper support for transaction or foreign key.
This is where InnoDB storage engine comes into play, InnoDB is a transaction safe
storage engine with support for foreign keys along with commit, rollback and crash
recovery capabilities.
InnoDB is a product of InnobaseOn, which a Finnish company now owned by Oracle.
MySQL has a licensing agreement with Innobase On which allows it to provide the
InnoDB.
How we can check if the MySQL server we are running has InnoDB support enabled or
not?
There is a MySQL system variable have_innodb and its value can be checked to see if
the support enabled or not. You can do this by using following command
Mysqladmin variables | grephave_innodb
If this returns YES then it means that the InnoDB support is enabled. If you have ‘–
skip-InnoDB’ in your /etc/my.cnf MySQL configuration file then InnoDB engine would
be disabled. And in that case you can comment out this option to enable InnoDB. It is
enabled by default and unless there is some related disable configuration added to
my.cnf configuration, there should be no issues.
Also if you would like to use InnoDB as the default storage engine, you can do that by
using below configuration in /etc/my.cnf :
Default-stroage_engine=innodb
But make sure to do your homework before setting the storage engine, it do have
performance benefits over MyISAM once its configured properly, but do have higher
administrative cost. InnoDB can be configured to have per table InnoDB file, which do
help in isolating any individual database corruptions.
(I)Important INNODB storage related parameter innodb_file_per_table:
The data files that you define in the configuration file form the InnoDB system
tablespace. The files are logically concatenated to form the table space. There is
no striping in use. Currently, you cannot define where within the table space your
Tables are allocated. However, in a newly created table space, InnoDB allocates
Space starting from the first data file.
To avoid the issues that come with storing all tables and indexes inside the
system table space, you can turn on the innodb_file_per_table configuration
option, which stores each newly created table in a separate tablespace file (with
extension .ibd). For tables stored this way, there is less fragmentation within the
disk file, and when the table is truncated, the space is returned to the operating
system rather than still being reserved by InnoDB within the system tablespace.
-- [root@vmxdb01 test]#grep innodb_file_per_table /etc/my.cnf
innodb_file_per_table = 1
MySQL> show variables like 'innodb_file_per_table';
+-----------------------+-------+
| Variable_name | Value |
+-----------------------+-------+
| innodb_file_per_table | ON |
+-----------------------+-------+
1 row in set (0.00 sec)
[root@vmxdb01 test]# ls -l /var/lib/mysql/test
total 216
-rw-rw----. 1 mysqlmysql 9106 Jun 15 23:39 customers.frm
-rw-rw----. 1 mysqlmysql 98304 Jun 15 23:42 customers.ibd
-rw-rw----. 1 mysqlmysql 8556 Jun 16 00:02 user.frm
-rw-rw----. 1 mysqlmysql 98304 Jun 16 00:02 user.ibd
This parameter can be dynamically changed:
MySQL> set global innodb_file_per_table=on;

More Related Content

What's hot (20)

PPTX
MySQL8.0_performance_schema.pptx
NeoClova
 
PDF
Pluggable database 3
Osama Mustafa
 
PDF
MySQL's new Secure by Default Install -- All Things Open October 20th 2015
Dave Stokes
 
PDF
Pluggable database tutorial 2
Osama Mustafa
 
PDF
Percona Xtrabackup - Highly Efficient Backups
Mydbops
 
PDF
MySQL For Oracle DBA's and Developers
Ronald Bradford
 
PDF
MySQL Enterprise Backup: PITR Partial Online Recovery
Keith Hollman
 
PDF
MySQL Backup and Recovery Essentials
Ronald Bradford
 
PDF
Getting started with my sql
Web Sky
 
PDF
MySQL PHP native driver : Advanced Functions / PHP forum Paris 2013
Serge Frezefond
 
PDF
MySQL For Oracle Developers
Ronald Bradford
 
PDF
MySQL 5.6 config 優化
Alexis Li
 
PDF
Embracing Database Diversity: The New Oracle / MySQL DBA - UKOUG
Keith Hollman
 
PDF
[db tech showcase Tokyo 2014] B15: Scalability with MariaDB and MaxScale by ...
Insight Technology, Inc.
 
PPT
Mysql high availability and scalability
yin gong
 
PDF
Maxscale_메뉴얼
NeoClova
 
PDF
MySQL Replication: Demo Réplica en Español
Keith Hollman
 
PPT
My two cents about Mysql backup
Andrejs Vorobjovs
 
PPTX
MySQL DBA
lalit choudhary
 
PDF
MySQL Performance Best Practices
Olivier DASINI
 
MySQL8.0_performance_schema.pptx
NeoClova
 
Pluggable database 3
Osama Mustafa
 
MySQL's new Secure by Default Install -- All Things Open October 20th 2015
Dave Stokes
 
Pluggable database tutorial 2
Osama Mustafa
 
Percona Xtrabackup - Highly Efficient Backups
Mydbops
 
MySQL For Oracle DBA's and Developers
Ronald Bradford
 
MySQL Enterprise Backup: PITR Partial Online Recovery
Keith Hollman
 
MySQL Backup and Recovery Essentials
Ronald Bradford
 
Getting started with my sql
Web Sky
 
MySQL PHP native driver : Advanced Functions / PHP forum Paris 2013
Serge Frezefond
 
MySQL For Oracle Developers
Ronald Bradford
 
MySQL 5.6 config 優化
Alexis Li
 
Embracing Database Diversity: The New Oracle / MySQL DBA - UKOUG
Keith Hollman
 
[db tech showcase Tokyo 2014] B15: Scalability with MariaDB and MaxScale by ...
Insight Technology, Inc.
 
Mysql high availability and scalability
yin gong
 
Maxscale_메뉴얼
NeoClova
 
MySQL Replication: Demo Réplica en Español
Keith Hollman
 
My two cents about Mysql backup
Andrejs Vorobjovs
 
MySQL DBA
lalit choudhary
 
MySQL Performance Best Practices
Olivier DASINI
 

Viewers also liked (9)

DOCX
Convert language latin1 to utf8 on mysql
Vasudeva Rao
 
PDF
9 steps to install and configure postgre sql from source on linux
chinkshady
 
DOCX
Postgre sql run book
Vasudeva Rao
 
DOCX
Performence tuning
Vasudeva Rao
 
DOCX
Database migration
Vasudeva Rao
 
PPT
MySQL Crash Course, Chapter 1
Gene Babon
 
PPTX
Mysql data replication
Tuấn Ngô
 
DOCX
Ddl commands
Vasudeva Rao
 
PDF
Teaching PostgreSQL to new people
Tomek Borek
 
Convert language latin1 to utf8 on mysql
Vasudeva Rao
 
9 steps to install and configure postgre sql from source on linux
chinkshady
 
Postgre sql run book
Vasudeva Rao
 
Performence tuning
Vasudeva Rao
 
Database migration
Vasudeva Rao
 
MySQL Crash Course, Chapter 1
Gene Babon
 
Mysql data replication
Tuấn Ngô
 
Ddl commands
Vasudeva Rao
 
Teaching PostgreSQL to new people
Tomek Borek
 
Ad

Similar to My sql storage engines (20)

PPT
MySQL and DB Engines
Compare Infobase Limited
 
PDF
Mysql database basic user guide
PoguttuezhiniVP
 
ODP
Mysql For Developers
Carol McDonald
 
PDF
My First 100 days with a MySQL DBMS (WP)
Gustavo Rene Antunez
 
PPTX
AWS Databases
Nitin Kumar Kashyap
 
PDF
MySQL Storage Engines Basics.
Remote MySQL DBA
 
PPTX
Learn Database Design with MySQL - Chapter 3 - My sql storage engines
Eduonix Learning Solutions
 
PPTX
Database storage engine
Islam AlZatary
 
PDF
Collaborate 2012 - Administering MySQL for Oracle DBAs
Nelson Calero
 
PPT
My sql basic
Prabhat gangwar
 
PPTX
Database storage engines
University of Sindh, Jamshoro
 
PPT
15 Ways to Kill Your Mysql Application Performance
guest9912e5
 
PDF
MySQL 5.5&5.6 new features summary
Louis liu
 
DOCX
Mohan Testing
smittal81
 
PDF
MySQL 8 Server Optimization Swanseacon 2018
Dave Stokes
 
PPTX
MySQL
janova santhi
 
PDF
MySQL 8 Tips and Tricks from Symfony USA 2018, San Francisco
Dave Stokes
 
PPTX
MySQL: Know more about open Source Database
Mahesh Salaria
 
PDF
MySQL Oslayer performace optimization
Louis liu
 
PPT
MySQL ppt
AtharvaSawant10
 
MySQL and DB Engines
Compare Infobase Limited
 
Mysql database basic user guide
PoguttuezhiniVP
 
Mysql For Developers
Carol McDonald
 
My First 100 days with a MySQL DBMS (WP)
Gustavo Rene Antunez
 
AWS Databases
Nitin Kumar Kashyap
 
MySQL Storage Engines Basics.
Remote MySQL DBA
 
Learn Database Design with MySQL - Chapter 3 - My sql storage engines
Eduonix Learning Solutions
 
Database storage engine
Islam AlZatary
 
Collaborate 2012 - Administering MySQL for Oracle DBAs
Nelson Calero
 
My sql basic
Prabhat gangwar
 
Database storage engines
University of Sindh, Jamshoro
 
15 Ways to Kill Your Mysql Application Performance
guest9912e5
 
MySQL 5.5&5.6 new features summary
Louis liu
 
Mohan Testing
smittal81
 
MySQL 8 Server Optimization Swanseacon 2018
Dave Stokes
 
MySQL 8 Tips and Tricks from Symfony USA 2018, San Francisco
Dave Stokes
 
MySQL: Know more about open Source Database
Mahesh Salaria
 
MySQL Oslayer performace optimization
Louis liu
 
MySQL ppt
AtharvaSawant10
 
Ad

Recently uploaded (20)

PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PPTX
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PDF
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
PDF
July Patch Tuesday
Ivanti
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PDF
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
PPTX
MSP360 Backup Scheduling and Retention Best Practices.pptx
MSP360
 
PDF
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PDF
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PPT
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PDF
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
July Patch Tuesday
Ivanti
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
MSP360 Backup Scheduling and Retention Best Practices.pptx
MSP360
 
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 

My sql storage engines

  • 1. INDEX: A. What is storage engine? B. Choosing the right engine C. Specifying and altering storage engines D. How to tell which storage engine a MySQL table uses? E. Check MySQL engine type for a specific table? F. Check the Default Storage Engine of MySQL G. Setting the Storage Engine H. Check if InnoDB is enabled in MySQL server I. Important INNODB storage related parameter innodb_file_per_table
  • 2. (A)What is storage engine? In MySQL the data’s are stored as files in any one of the types in storage engines. MySQL supports pluggable storage engines that we can use any types of engine belongs to your data. There are two types of storage engines in MySQL Transactional (The data can be modified in engines) and non-transactional (It can only fetch the data from engines). The default storage engine for MySQL prior to version 5.5 was MyISAM. For MySQL 5.5 and later, the default storage engine is InnoDB. Features of MySQL Storage Engines Choosing the right storage engine is an important strategic decision, which will impact future development. If you are planning a production database, then things become more complicated. A storage engine is a software module that a database management system uses to create, read, and update data from a database. There are two types of storage engines in MySQL. Transactional and non-transactional. MySQL supported the following types of Storage Engine 1. MyISAM 2. InnoDB 3. Merge 4. Memory 5. Blackhole 6. Archive 7. CSV 8. Federated 1. MyISAM MyISAM is the oldest and original storage engine. It is a fast storage engine.it does not support transactions. MyISAM provides table level locking. It is used most in web, data warehousing. If you create a table without representing the storage engine it take MyISAM engine as default (before MySQL 5.5 version).MySQL databases are generally store in data directories and MYISAM tables are stored using 3 files. .frm - Table structure .MYD - Data file
  • 3. .MYI - Index file MyISAM has most flexible auto increment. The tables can be used to set up merge tables. The table storage format is portable. Maximum no of indexes per table = 64.Maximum no of columns per index = 16.Blob and TEXT columns can be indexed. Table size is 256TB. It does not provide for foreign key. 2. InnoDB InnoDB is the most widely used storage engine with transaction supportive InnoDB is a Transactional safe storage engine. It is an ACID (Atomicity, Consistency, Isolation, Durability) compliant storage engine. It supports row-level locking, crash recovery and multi-version concurrency control.i.e it has commits rollback and crash recovery capability to recover the data. InnoDB provide row level locking to use multi user concurrency and performance. It supports foreign key. InnoDB creates two log files namely "ib_logfile0" and "ib_logfile1" and a data file "ibdata1" in the MySQL data directory where it stores its tables. MySQL creates an auto-extending 10MB data file in ibdata1 and two 5MB log files in ib_logfile0 andib_logfile1 in the MySQL data directory. The table definitions are stored in database directory with a .frm extension whereas the data is stored in the "ibdata1" - tablespace.Minimum table space size is 10MB. And maximum table space size is 64TB.It is the only engine which provides foreign key referential integrity constraint. 3. Merge Merge operates on underlying MyISAM tables. Merge tables help manage large volumes of data more easily. The MERGE engine type allows you to combine a number of identical tables into a single table. You can then execute queries that return the results from multiple tables as if they were just one table. Each table merged must have the same table definition. The MERGE table is particularly effective if you are logging data directly or indirectly into a MySQL database and create an individual table per day, week or month and want to be able to produce aggregate queries from multiple tables. Transaction No Locking level Table. It logically groups a series of identical MyISAM tables, and references them as one object. Good for data warehousing environments.
  • 4. 4. Memory Memory Storage engine creates tables in memory. It is the fastest engine. The MEMORY storage engine (previously known as the HEAP storage engine) stores all data in memory; once the MySQL server has been shut down any information stored in a MEMORY database will have been lost. However, the format of the individual tables is kept and this enables you to create temporary tables that can be used to store information for quick access without having to recreate the tables each time the database server is started. Cannot contain BLOB or TEXT columns. It has table level locking. It does not support transactions. Memory storage engine is ideal for creating temporary tables or quick lookups. The data is lost when the database is restarted. 5. Blackhole It acts as a “black hole” that accepts data but throws it away and does not store it. BLACKHOLE engine does not actually store any data. Retrievals always return an empty set. Although you can create tables and indexes, all SQL statements that would add or update information to the database are executed without actually writing any data. The database structure is retained, however, and you can create any indexes on the (non-existent) information that you want. The functionality can be used in distributed database design where data is automatically replicated, but not stored locally. This storage engine can be used to perform performance tests or other testing. 6. Archive Archive storage engine is optimized for high speed inserting. It is used for storing large amounts of data without indexes in a very small footprint. It supports only the INSERT and SELECT statements, but does support most of the MySQL field types. It compresses data as it is inserted. It does not support truncations. Information stored in an ARCHIVE storage engine table is compressed and cannot be modified and so ARCHIVE tables are perfect for storing log data when an archive table is created, following files are created in the database directory. .frm-tabledefinition .ARZ-DATAfile .ARM - METADATA file
  • 5. It does NOT support DELETE, REPLACE and UPDATE. It provides row level locking. It is ideal for storing, retrieving large amounts of seldom referenced historical archived data. 7. CSV (Comma Separated Value) CSV stores data in CSV files. It provides great flexibility, because data in this format is easily integrated into other applications.. It stores data in text files using comma- separated values format. When a table is created 2 files are created in the database directory .frm-tabledefinition .CSV - data file It is not an efficient method for storing large volumes of data, or larger data types like BLOB, although such types are supported. There is also no indexing. However, because the data is stored in the CSV format it is exceedingly portable. 8. Federated Federated storage engine offers the ability to separate MySQL servers to create one logical database from many physical servers. The FEDERATED storage engine (added in MySQL 5.03) enables you to access data from remote MySQL database (other databases may be supported in the future) as if it were a local database. In effect, the MySQL server acts as a proxy to the remote server, using the MySQL client access library to connect to the remote host, execute queries and then reformat the data into the localized format. It does not support transactions. Queries on the local server are automatically executed on the remote (federated) tables. No data is stored on the local tables. It is good for distributed environments. (B)Choosing the right engine : No storage engine is ideal for all circumstances. Some perform best under certain conditions and perform worse in other situations. There are trade-offs than must be considered. A more secure solution takes more resources. It might be slower, take more CPU time and disk space. MySQL is very flexible in the fact that it provides several different storage engines. Some of them, like the Archive engine, are created
  • 6. to be used in specific situations. Ironically this also brings a question, which storage engine to use? Which may not be easily answered? In some cases, the answer is clear. Whenever we are dealing with some payment systems, we are obliged to use the most secure solution. We cannot afford to lose such sensitive data. InnoDB is the way to go. If we want full-text search, than we must choose MyISAM. Only InnoDB supports foreign key referential integrity constraint and if we plan to use this constraint, then the choice is clear. In many situations we must have enough experience to choose the right engine. The question is further complicated by the fact, that we can choose different storage engines for different tables. (C) Specifying and altering storage engines The storage engine is specified at the time of the table creation. MySQL> CREATE TABLE Cars (Id INTEGER PRIMARY KEY, Name VARCHAR (50), Cost INTEGER) ENGINE='MyISAM'; The ENGINE keyword specifies the storage engine used for this particular table. If we do not specify the storage engine explicitly, then the default storage engine is used. Prior to MySQL 5.5 the default storage engine was MyISAM. For MySQL 5.5 and later, the default storage engine is InnoDB. MySQL> SHOW VARIABLES LIKE 'storage_engine'; The default storage engine can be found in the storage_engine variable. It is possible to migrate to a different storage engine. Note that migrating a large table might take a long time. Also we might run into some problems when migrating tables. Some features might not be supported in both tables. MySQL> SELECT ENGINE FROM information_schema.TABLES WHERE TABLE_SCHEMA='mydb'AND TABLE_NAME='Cars';
  • 7. This SQL statement finds out the storage engine used for a Cars table in mydb database. We could also use SELECT CREATE TABLE Cars SQL statement. The information_schema is a table which stores technical information about our tables. MySQL> ALTER TABLE Cars ENGINE='MyISAM'; This SQL statement changes the storage engine to MyISAM. MySQL> SELECT ENGINE FROM information_schema.TABLES WHERETABLE_SCHEMA='mydb' AND TABLE_NAME='Cars'; | ENGINE | | MyISAM | Now the storage engine is MyISAM. (D)How to tell which storage engine a MySQL table uses : MySQL supports multiple storage engines (E.g. . . MyISAM, INNODB, etc…)each With its pros and cons, and each table in a MySQL database can use a different storage engine.How to work out which table storage engine is used by a MySQL table, using either a SQL query or using the web browser tool phpMyAdmin. SQL Query After digging around in the phpMyAdmin code I worked out they determine the MySQL table storage engine by querying the INFORMATION_SCHEMA database. This is a special database which describes information relating to the various databases on the server. The query the "products" table of the "test" database to see which storage engine it is using, you would run this SQL query: SELECT ENGINE FROM information_schema.TABLES WHERE TABLE_SCHEMA=’test’ AND TABLE_NAME=’products’; The TABLE_SCHEMA is the name of the database, and TABLE_NAME is the table name you wish to query. The SQL query above will return the storage engine, assuming the database and table specified exists, and you have sufficient permissions.
  • 8. If you wanted to see the storage engine for all tables in your database, do this instead: SELECT TABLE_NAME, ENGINE FROM information_schema.TABLES WHERE TABLE_SCHEMA=’test’; (E) Check MySQL engine type for a specific table? SHOW TABLE STATUS WHERE NAME=’table_name‘ This will give you (among other things) an engine column, which is what you want. SELECT TABLE_NAME, ENGINE FROM information_schema.TABLES where TABLE_SCHEMA = 'database' AND ENGINE IS NOT NULL; This excludes MySQL views from the list, which don't have an engine
  • 9. (F) Check the Default Storage Engine of MySQL 1. Login as a rrot user and connect MySQL promt 2. Start the servers 3. Enter the following line into the MySQL prompt and hit Enter: USE information_schema; 4. Enter the following line into the MySQL prompt and hit Enter: SELECT * FROM engines; 5. A table with the Storage Engines of MySQL will show up. Inside the Support column the Default Storage Engine has the value "DEFAULT". Value Meaning YES The engine is supported and is active DEFAULT Like YES, plus this is the default engine NO The engine is not supported DISABLED The engine is supported but has been disabled
  • 10. (http://dev.mysql.com/doc/refman/5.0/en/show-engines.html) (G) Setting the Storage Engine: When you create a new table, you can specify which storage engine to use by adding an ENGINE table option to the CREATE TABLE statement: CREATE TABLE t (i INT) ENGINE = INNODB; If you omit the ENGINE option, the default storage engine is used. Normally, this is MyISAM, but you can change it by using the --default-storage-engine server startup option, or by setting the default-storage-engine option in the my.cnf configuration file. You can set the default storage engine to be used during the current session by setting the storage_enginevariable: SET storage_engine=MYISAM; When MySQL is installed on Windows using the MySQL Configuration Wizard, the InnoDB or MyISAM storage engine can be selected as the default. (See Section 2.3.5.5, “MySQL Server Instance Config Wizard: The Database Usage Dialog”.) To convert a table from one storage engine to another, use an ALTER TABLE statement that indicates the new engine: ALTER TABLE t ENGINE = MYISAM; (H) Check if innodb is enabled in Mysql server MySQL database server has the capability to use different database storage engines. The database storage engine is what actually does the work of storing and retrieving data from the underlying database tables. The storage engines work like a modular code which can be plugged into MySQL. Among the storageengineer’s MyISAM is the one, used most widely and also the
  • 11. default storage engine for MySQL. However it does lack some high level functionality which is requirement for any enterprise level database server e.g. it does not have proper support for transaction or foreign key. This is where InnoDB storage engine comes into play, InnoDB is a transaction safe storage engine with support for foreign keys along with commit, rollback and crash recovery capabilities. InnoDB is a product of InnobaseOn, which a Finnish company now owned by Oracle. MySQL has a licensing agreement with Innobase On which allows it to provide the InnoDB. How we can check if the MySQL server we are running has InnoDB support enabled or not? There is a MySQL system variable have_innodb and its value can be checked to see if the support enabled or not. You can do this by using following command Mysqladmin variables | grephave_innodb If this returns YES then it means that the InnoDB support is enabled. If you have ‘– skip-InnoDB’ in your /etc/my.cnf MySQL configuration file then InnoDB engine would be disabled. And in that case you can comment out this option to enable InnoDB. It is enabled by default and unless there is some related disable configuration added to my.cnf configuration, there should be no issues. Also if you would like to use InnoDB as the default storage engine, you can do that by using below configuration in /etc/my.cnf : Default-stroage_engine=innodb But make sure to do your homework before setting the storage engine, it do have performance benefits over MyISAM once its configured properly, but do have higher administrative cost. InnoDB can be configured to have per table InnoDB file, which do help in isolating any individual database corruptions. (I)Important INNODB storage related parameter innodb_file_per_table: The data files that you define in the configuration file form the InnoDB system tablespace. The files are logically concatenated to form the table space. There is no striping in use. Currently, you cannot define where within the table space your Tables are allocated. However, in a newly created table space, InnoDB allocates
  • 12. Space starting from the first data file. To avoid the issues that come with storing all tables and indexes inside the system table space, you can turn on the innodb_file_per_table configuration option, which stores each newly created table in a separate tablespace file (with extension .ibd). For tables stored this way, there is less fragmentation within the disk file, and when the table is truncated, the space is returned to the operating system rather than still being reserved by InnoDB within the system tablespace. -- [root@vmxdb01 test]#grep innodb_file_per_table /etc/my.cnf innodb_file_per_table = 1 MySQL> show variables like 'innodb_file_per_table'; +-----------------------+-------+ | Variable_name | Value | +-----------------------+-------+ | innodb_file_per_table | ON | +-----------------------+-------+ 1 row in set (0.00 sec) [root@vmxdb01 test]# ls -l /var/lib/mysql/test total 216 -rw-rw----. 1 mysqlmysql 9106 Jun 15 23:39 customers.frm -rw-rw----. 1 mysqlmysql 98304 Jun 15 23:42 customers.ibd -rw-rw----. 1 mysqlmysql 8556 Jun 16 00:02 user.frm -rw-rw----. 1 mysqlmysql 98304 Jun 16 00:02 user.ibd This parameter can be dynamically changed: MySQL> set global innodb_file_per_table=on;