Storage Engine:
Early on, there is how to choose the MyISAM and Innodb?
Now, Innodb continuous development and improvement, has become the mainstream storage engine.
So after a 5.5 mysql, no brain Innodb can choose.
MYSQL data in the index, and other objects, how storage is to achieve a file system.
MYSQL support many storage engine, use
SHOW ENGINES
It can be found in all of the engine
MyISAM and Innodb comparison:
1. The angle store files: MyISAM and index data are stored, the data is .MYD, the index is .myi; Innodb centralized storage of data and index .ibd, the mobile does not support file-level
2. The storage order recorded angle: MyISAM sequentially stored in the record directly into the end of the table; Innodb sequentially storing the primary key, the insertion sorting operation need, slightly affects the efficiency
3. Space debris angle: MyISAM will produce; Innodb not produce; space debris to delete the previous record, MyISAM will spare some space down
After the popular terms, said the original 100K file storage, I removed the part of the record or 100K
Optimization of space debris MyISAM:
OPTIMIZE TABLE XXX;
4. The angle of the foreign key and a transaction: MyISAM not supported; Innodb support to ensure data integrity
The full-text indexing angles: MyISAM does not support; Innodb new version supports, but does not support Chinese, so it is tasteless
6. The lock angle: MyISAM table-level locking; Innodb row level locking, table level lock, stronger concurrent processing
Summary: Without special needs, using Innodb, reading and writing data are basically the case, consider using MyISAM
lock:
Avoid resource contention mechanism functions, multiple tasks simultaneously use a resource, resulting in contention for the resource
Database, multiple tasks on the database CRUD operations is resource contention
Popular explain principle: When a task using the resource, logos out other tasks can not operate at the same time, need to wait or give up
The basic process: first try to lock if the lock is successful, then the use of the resource, released after use; if it fails, enter the operation queue, waiting for the lock release
Types of locks:
Shared lock (read lock), exclusive lock (write lock)
Different types of locks, resulting in concurrent operation is not the same
Read lock: shared read operation, blocking write operation, the write operation can not be performed
Write lock: write operation performed when the exclusive resources, their own read and write, other tasks can not read nor write
When the case of MySQL to perform any SQL, the lock will automatically increase, routine operations, the need to manually manage locks
Here and locks above the storage engine lock table row lock is not the same, the lock specific implementation
Table-level lock: Operation will lock the entire table, either shared or exclusive locks lock
Row-level locking: locking action recording operation
Lock syntax:
Table lock: READ is a shared lock to read lock, WRITE write lock is an exclusive lock
LOCK TABLES [table-name] READ|WRITE; UNLOCK TABLES;
Line Lock: the first is shared lock, the second is an exclusive lock
SELECT * FROM TABLE [table-name] LOCK IN SHARE MODE; SELECT * FROM TABLE [table-name] FOR UPDATE;
Row lock exclusive lock only lock the rows in the table, other tasks can read, can not update the locked row, row locks are not accurate to a row, but a gap lock
This is inserted into the lock when the recording condition of the rows will fail (such as the line 20 is less than the locking ID, ID18 is inserted, is locked)