Sunday, 25 May 2014

MySql Storage Engine

Change table engine to MyISAM

ALTER TABLE `tableName` ENGINE = MYISAM

Change table engine to innodb


ALTER TABLE `tableName` ENGINE = innodb

How to create table to MYISAM


mysql> CREATE TABLE table2 (col1 INT, col2 CHAR(30)) ENGINE = MYISAM;


Features of MYISAM and INNODB



Feature
InnoDB
MyISAM
Storage limits
64TB
256TB
Transactions
Yes
No
Locking granularity
Row
Table
MVCC
Yes
No
B-tree indexes
Yes
Yes
Clustered indexes
Yes
No
Data caches
Yes
No

MyISAM


  1. MyISAM doesn’t support foreign key constraints or transactions, which are essential for data integrity. Hence we call MySQL with MYISAM is DBMS
  2. MYISAM not supports transaction. You cannot commit and rollback with MYISAM.
  3. MYISAM supports Table-level Locking : In addition, the whole table is locked whenever a record is inserted or updated; this causes a detrimental effect on performance as usage grows.So no other session can perform a SELECT or a DML operation on the table.
  4. MyISAM stores its tables, data and indexes in diskspace using separate three different files. (tablename.FRM, tablename.MYD, tablename.MYI)
  5. Support Full-text indexing.When use "select" statement, gives faster results as compare to Innodb. so you can use MyISAM, if the table is more static with lots of select and less update and delete.
  6. When read, a MyISAM table's indexes can be read once from the .MYI file and loaded in the MyISAM Key Cache (as sized by key_buffer_size).
    ALTER TABLE mytable ROW_FORMAT=Fixed;
  7. We can you make a MyISAM table's .MYD faster with this
       Notes:
  1. An .frm file stores the table format.
  2. The data file has an .MYD (MYData) extension. 
  3. The index file has an .MYI (MYIndex) extension.
  4. All numeric key values are stored with the high byte first to permit better index compression.


Innodb


  1. It is an ACID compliant storage engine. 
  2. It supports row-level locking, crash recovery and multi-version concurrency control.
  3. Foreign key constraints : If you need the database to enforce foreign key constraints, or you need the database to support transactions (i.e. changes made by two or more DML operations handled as single unit of work, with all of the changes either applied, or all the changes reverted) then you would choose the InnoDB.
  4. Used for Secure Transactions section just like dealing with some payment systems.
     Notes:
  1. When you create an InnoDB table, MySQL creates a .frm file in a database directory under the MySQL data directory. It also create an .ibd file. 
  2. .idb files contain a single table and associated index data
ACID (Atomicity, Consistency, Isolation, and Durability)

Atomicity: Atomicity requires that each transaction be "all or nothing".
When a transaction makes multiple changes to the database, either all the changes succeed when the transaction is committed, or all the changes are undone when the transaction is rolled back.

Consistency: The database remains in a consistent state at all times.
After each commit or rollback. While transaction data are in consistent mode. i.e  If related data is being updated across multiple tables, queries see either all old values or all new values, not a mix of old and new values.

Isolation: Isolation requires that multiple transactions occurring at the same time not impact each other's execution. i.e Transactions are protected from each other while they are in progress.

Durability: Once a commit operation succeeds , results of transactions are durable.
It is property that ensures transactions are saved permanently and do not accidentally disappear or get erased, even during a database crash. 

0 comments:

Post a Comment