0% found this document useful (0 votes)
20 views5 pages

Storage Engines With Simple Examples

A storage engine in MySQL is software that manages how data is created, read, updated, and deleted. The default storage engine changed from MyISAM to InnoDB starting from MySQL version 5.5, with InnoDB supporting transactions and foreign key constraints, while MyISAM is faster for select operations but lacks transaction support. Other storage engines include MEMORY, CSV, ARCHIVE, MERGE, FEDERATED, and BLACKHOLE, each with unique features and use cases.

Uploaded by

s3itsol
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views5 pages

Storage Engines With Simple Examples

A storage engine in MySQL is software that manages how data is created, read, updated, and deleted. The default storage engine changed from MyISAM to InnoDB starting from MySQL version 5.5, with InnoDB supporting transactions and foreign key constraints, while MyISAM is faster for select operations but lacks transaction support. Other storage engines include MEMORY, CSV, ARCHIVE, MERGE, FEDERATED, and BLACKHOLE, each with unique features and use cases.

Uploaded by

s3itsol
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

MYSQL STORAGE ENGINES

What is a storage engine??


A storage engine(DataBase Engine) is a software that a Database Management System uses to
create, read, update, and delete (CRUD) data from a database.

The default storage engine for MySQL before version 5.5 was MyISAM. For MySQL 5.5 and
later, the default storage engine is InnoDB. Choosing the right storage engine is an important
strategic decision, which will impact future development.

mysql> SHOW ENGINES;


mysql> show variables like "default_storage%";

mysql> SET default_storage_engine=”myisam”;

Types of MySQL storage engines


1)Transactional storage engines
2) Non-Transactional storage engines

1) Transactional storage engines


 InnoDB, NDB

2) Non-Transactional storage engines

 MyISAM
 MEMORY
 ARCHIVE
 CSV
 MERGE
 FEDERATED
 BLACKHOLE

Transactional storage engines support transactions like COMMIT, ROLLBACK, SAVEPOINT.


The transaction is nothing but a collection of executable SQL statements. And Transactional
storage engines supports foreign key constraint.

MyISAM InnoDB
Few DML operations OLTP with a lot of DML
Very fast for selects Slower for selects
Some data can get corrupted Good crash-recovery facility
Cannot be a MASTER server in replication, but can be a SLAVE Perfect for MASTER server in the replication
Supports FOREIGN KEY
Binary logs
Point-in-time recovery
Feature MyISAM innoDB
Storage limits 256TB 64TB
Transactions No Yes
Locking granularity Table Row
MVCC No Yes
Geospatial indexing support Yes No
Full-text search indexes Yes No
Clustered indexes No Yes
Data caches No Yes
Cluster database support No No
Foreign key support No Yes
Point-in-time recovery No Yes

MyISAM

MyISAM is a MySQL default storage engine (Before Mysql 5.5 version). It is a non-
transactional storage engine. It doesn't support transactions. It process the insert and select
statements as fast as possible. It supports fulltest index supporting. And also table level locking.
No foreign key support. It supports 64 indexes per row. Count(*) works fast than Innodb. We can
compress the data here.
mysql>create database exdb;
mysql>use exdb;
mysql>create table emp(id int(10),name varchar(30),sal double(14,2)) engine=”myisam”;
mysql>show tables;
mysql>desc emp;
mysql>show create table emp;
mysql>show columns from emp;
mysql> create table emp2(id int(10),name varchar(30),sal double(14,2),FULLTEXT(name))
engine="MYISAM";

#cd /var/lib/mysql/dbname/

here we can see emp.frm,(It contains structure) emp.MYI (it contains indexex) ,emp.MYD(it
contains data)..So take disk space more.

Innodb

Innodb is a MySQL default storage engine (From 5.5 version). It is a transactional storage
engine. It supports transactions and row-level locking. It provides ACID properties. It
processes update queries as fast as possible. Count(*) little slow than MyISAM. It doesn't
support a full-text index. Here we can't compress the data because everything store in a single
file(ibdata).
Atomicity : a transaction is a unit of operation - either all the transaction's actions are completed
or none are.
Consistency: Any work in progress must not be visible to other transactions until the transaction
has been committed.

Isolation: A transaction should appear to be running by itself, the effects of other ongoing
transactions must be invisible to this transaction, and the effects of this transaction must be
invisible to other ongoing transaction.
Durability: When the transaction is committed, it must be persisted so it is not lost in the event of
a power failure. Only committed transactions are recovered during power-up and crash recovery;
uncommitted work is rollbacked.

mysql>create table emp(id int(10),name varchar(30),sal double(14,2)) engine=”innodb”;


mysql> create table dept(eid int(10),dname varchar(30),loc varchar(30),foreign key(eid)
references emp(1d)) engine=innodb;

#cd /var/lib/mysql/dbname

here we can see the only emp.frm. The data and indexes will be store in the ibdata file.
innodb_file_per_table supports from MySQL 5.5 to stores index and data in .ibd file separately
for every table.

alter an engine
MYSQL> ALTER TABLE EMP2 ENGINE=INNODB;

MEMORY (formerly known as HEAP)

For this engine, the data will be stored in the memory. When we restart the server we will lose all
the data. When we create a table only the .frm file will be store in the data directory. It doesn't
support BLOB, TEXT data types.

CREATE TABLE test_mem (name char(30)) ENGINE = MEMORY;


Insert into test_mem values ('sarath');
Insert into test_mem values ('venkat');
Insert into test_mem values ('chandra');
Insert into test_mem values ('mamata');
Insert into test_mem values ('anusha');

CSV

The CSV storage engine stores data in text files using comma-separated values format.

The CSV storage engine is always compiled into the MySQL server.
CREATE TABLE test_csv (id INT NOT NULL, name CHAR(10) NOT NULL) ENGINE =
CSV;

INSERT INTO test_csv VALUES(1,'sarath '),(2,'prakash');

INSERT INTO test_csv VALUES(3,'sai '),(5,'papu') ,(4,'janvi');

Select * from test_csv

Creating a CSV table also creates a corresponding Metafile that stores the state of the table and
the number of rows that exist in the table. The name of this file is the same as the name of the ta-
ble with the extension CSM. Parition tables and indexing not supported in CSV Engine.

ARCHIVE

This engine stores data in zip format. It does't support primary key. It is use to stores historical
data. The select statements will be very slow because the data will be stored in compressed
format.
create table test_arch(name varchar(30)) engine=ARCHIVE;
insert into test_arch values ('tom');
insert into test_arch values ('sushma');
insert into test_arch values ('ramya');
insert into test_arch values ('sravya');
insert into test_arch values ('anusha');

MERGE

The MERGE storage engine, also known as the MRG_MyISAM engine, is a collection of
identical MyISAM tables that can be used as one. “Identical” means that all tables have identical
column and index information.

mysql> CREATE TABLE EMP1 (EMPID INT NOT NULL AUTO_INCREMENT PRIMARY
KEY, NAME CHAR(20)) ENGINE=MyISAM;

mysql> CREATE TABLE EMP2 (EMPID INT NOT NULL AUTO_INCREMENT PRIMARY
KEY,NAME CHAR(20)) ENGINE=MyISAM;

mysql> INSERT INTO EMP1 (NAME) VALUES ('sarath_One'),('anu_one'),('mamu_one');

mysql> INSERT INTO EMP2 (NAME) VALUES ('sairam_Two'),('prakash_two'),('Kiran_two');

mysql> CREATE TABLE total9 (EMPID INT NOT NULL AUTO_INCREMENT


PRIMARY KEY,NAME CHAR(20) ) ENGINE=MERGE UNION=(EMP1,EMP2);
mysql> INSERT INTO EMP2 (NAME) VALUES ('seshu_2'),('giri_2'),('garuda_2');
mysql> INSERT INTO EMP1 (NAME) VALUES ('sarath_1'),('venkat_1'),('chandra_1');

FEDERATED

The FEDERATED storage engine is used to access the remote MySQL database without using
replication or cluster technology.

#ifconfig
172.16.88.134 [ My Server ipaddress ]
CREATE TABLE TEST9(ID INT(10),NAME VARCHAR(20),SAL DOUBLE(14,2);

CREATE TABLE `test9`(`id` int(10),UNIQUE KEY(`name `( varchar 20)))


ENGINE=FEDERATED
CONNECTION='MYSQL:// s
:3306/db_name/test9';

localhost
CREATE TABLE `Table1`(`A` VARCHAR(100),UNIQUE KEY(`A`(30))) ENGINE=FEDERATED
CONNECTION='MYSQL://127.0.0.1:3306/TEST/Table1';

BLACKHOLE

In this location /dev/null storage engine (anything you write to it disappears), This engine you
can use in master-slave replication. In some cases, this will give benefits to replication topology.
mysql> create table black1(name char(20)) engine=BLACKHOLE;
Query OK, 0 rows affected (0.01 sec)

mysql> insert into black1 values ('records');


Query OK, 1 row affected (0.00 sec)

mysql> insert into black1 values ('records');


Query OK, 1 row affected (0.01 sec)

mysql> insert into black1 values ('records');


Query OK, 1 row affected (0.00 sec)

mysql> select * from black1;


Empty set (0.00 sec)

You might also like