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

DOCX
Upgrading mysql version 5.5.30 to 5.6.10
DOCX
Mater,slave on mysql
DOCX
Inno db datafiles backup and retore
DOCX
All types of backups and restore
PDF
MySQL Advanced Administrator 2021 - 네오클로바
PDF
MySQL Backup and Security Best Practices
PDF
Meb Backup & Recovery Performance
PDF
MariaDB 10.5 binary install (바이너리 설치)
Upgrading mysql version 5.5.30 to 5.6.10
Mater,slave on mysql
Inno db datafiles backup and retore
All types of backups and restore
MySQL Advanced Administrator 2021 - 네오클로바
MySQL Backup and Security Best Practices
Meb Backup & Recovery Performance
MariaDB 10.5 binary install (바이너리 설치)

What's hot (20)

PPTX
MySQL8.0_performance_schema.pptx
PDF
Pluggable database 3
PDF
MySQL's new Secure by Default Install -- All Things Open October 20th 2015
PDF
Pluggable database tutorial 2
PDF
Percona Xtrabackup - Highly Efficient Backups
PDF
MySQL For Oracle DBA's and Developers
PDF
MySQL Enterprise Backup: PITR Partial Online Recovery
PDF
MySQL Backup and Recovery Essentials
PDF
Getting started with my sql
PDF
MySQL PHP native driver : Advanced Functions / PHP forum Paris 2013
PDF
MySQL For Oracle Developers
PDF
MySQL 5.6 config 優化
PDF
Embracing Database Diversity: The New Oracle / MySQL DBA - UKOUG
PDF
[db tech showcase Tokyo 2014] B15: Scalability with MariaDB and MaxScale by ...
PPT
Mysql high availability and scalability
PDF
Maxscale_메뉴얼
PDF
MySQL Replication: Demo Réplica en Español
PPT
My two cents about Mysql backup
PPTX
MySQL DBA
PDF
MySQL Performance Best Practices
MySQL8.0_performance_schema.pptx
Pluggable database 3
MySQL's new Secure by Default Install -- All Things Open October 20th 2015
Pluggable database tutorial 2
Percona Xtrabackup - Highly Efficient Backups
MySQL For Oracle DBA's and Developers
MySQL Enterprise Backup: PITR Partial Online Recovery
MySQL Backup and Recovery Essentials
Getting started with my sql
MySQL PHP native driver : Advanced Functions / PHP forum Paris 2013
MySQL For Oracle Developers
MySQL 5.6 config 優化
Embracing Database Diversity: The New Oracle / MySQL DBA - UKOUG
[db tech showcase Tokyo 2014] B15: Scalability with MariaDB and MaxScale by ...
Mysql high availability and scalability
Maxscale_메뉴얼
MySQL Replication: Demo Réplica en Español
My two cents about Mysql backup
MySQL DBA
MySQL Performance Best Practices
Ad

Viewers also liked (9)

DOCX
Convert language latin1 to utf8 on mysql
PDF
9 steps to install and configure postgre sql from source on linux
DOCX
Postgre sql run book
DOCX
Performence tuning
DOCX
Database migration
PPT
MySQL Crash Course, Chapter 1
PPTX
Mysql data replication
DOCX
Ddl commands
PDF
Teaching PostgreSQL to new people
Convert language latin1 to utf8 on mysql
9 steps to install and configure postgre sql from source on linux
Postgre sql run book
Performence tuning
Database migration
MySQL Crash Course, Chapter 1
Mysql data replication
Ddl commands
Teaching PostgreSQL to new people
Ad

Similar to My sql storage engines (20)

PPT
MySQL and DB Engines
PDF
Mysql database basic user guide
ODP
Mysql For Developers
PDF
My First 100 days with a MySQL DBMS (WP)
PPTX
AWS Databases
PDF
MySQL Storage Engines Basics.
PPTX
Learn Database Design with MySQL - Chapter 3 - My sql storage engines
PPTX
Database storage engine
PDF
Collaborate 2012 - Administering MySQL for Oracle DBAs
PPT
My sql basic
PPTX
Database storage engines
PPT
15 Ways to Kill Your Mysql Application Performance
PDF
MySQL 5.5&5.6 new features summary
DOCX
Mohan Testing
PDF
MySQL 8 Server Optimization Swanseacon 2018
PPTX
PDF
MySQL 8 Tips and Tricks from Symfony USA 2018, San Francisco
PPTX
MySQL: Know more about open Source Database
PDF
MySQL Oslayer performace optimization
PPT
MySQL ppt
MySQL and DB Engines
Mysql database basic user guide
Mysql For Developers
My First 100 days with a MySQL DBMS (WP)
AWS Databases
MySQL Storage Engines Basics.
Learn Database Design with MySQL - Chapter 3 - My sql storage engines
Database storage engine
Collaborate 2012 - Administering MySQL for Oracle DBAs
My sql basic
Database storage engines
15 Ways to Kill Your Mysql Application Performance
MySQL 5.5&5.6 new features summary
Mohan Testing
MySQL 8 Server Optimization Swanseacon 2018
MySQL 8 Tips and Tricks from Symfony USA 2018, San Francisco
MySQL: Know more about open Source Database
MySQL Oslayer performace optimization
MySQL ppt

Recently uploaded (20)

PDF
cuic standard and advanced reporting.pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Electronic commerce courselecture one. Pdf
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
Cloud computing and distributed systems.
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
cuic standard and advanced reporting.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Per capita expenditure prediction using model stacking based on satellite ima...
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
sap open course for s4hana steps from ECC to s4
Electronic commerce courselecture one. Pdf
Dropbox Q2 2025 Financial Results & Investor Presentation
Cloud computing and distributed systems.
Unlocking AI with Model Context Protocol (MCP)
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Encapsulation_ Review paper, used for researhc scholars
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Diabetes mellitus diagnosis method based random forest with bat algorithm
MYSQL Presentation for SQL database connectivity
Chapter 3 Spatial Domain Image Processing.pdf
Mobile App Security Testing_ A Comprehensive Guide.pdf

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;