MySQL indexing and transactions, views, stored and lnnoDB engines MylSAM

MySQL indexing and transactions, views, stored and lnnoDB engines MylSAM

The concept of index

Database indexing and similar books in the catalog:

1.- book without reading the whole book, you can use the directory to quickly find the desired information
2. Contents of the book is a list of words, which indicate the page numbers of each word

Database index:

1. In the database, index bow | procedures make the database without scanning the entire table, where you can find desired data
cable 2. The bow database | a is a table - a collection of columns, or a plurality of column values, and a logical data page pointer list to identify these physical values

Index role:

1. After the appropriate index is provided, a fast database using various positioning techniques, can greatly accelerate the rate of queries
2. In particular, when a large table, or queries involving multiple tables, the index query can accelerate into a dry fold
3. IO can reduce the cost of the database, and may also reduce the cost of sorting the index database
4 by creating a unique index to ensure uniqueness Datasheet
5 can accelerate the connection between the table and the table
6. use of the packet and when sorting, grouping and sorting can greatly reduce the time

Category Index

Ordinary Index:

Is the most basic index | type, but it is not the only - restriction of such

Unique index:

This cable bow | and the previous "general index" is basically the same, but with one difference: all values ​​of the indexed column can only occur once, that must be unique

Primary key:

Primary key is a unique index, but it must be designated as the "PRIMARY KEY"

Full-text index:

MySQL version 3.23.23 from the start to support full-text indexing and full-text search. , Full-text index can be created on VARCHAR type or TEXT columns as MySQL FULLTEXT index type in the full-text index

Single index and multi-column index:

Indexes can be created on a separate index, the index can be created on multiple columns

Creating an index based on the principle of

1. The primary key of the table, there must be a foreign key index
2. The data amount exceeds the line 300 should have a table index
3. Table frequently connected to other tables in the connection field should be indexed
4. Uniqueness poor field not suitable for indexing
5. the field is not updated too frequently for creating an index 6. often appear in the Where clause field, especially in the field of large tables should be indexed
7. the index should be built on a highly selective field
8 the index should be built on a small field, even for large text fields long field, not to build index

Affairs

The concept Affairs

1. The transaction is a mechanism, a sequence of operations comprises a set of database operations command and all commands as - - full - the date of submission to the system or undo operation request, i.e., either the set of database commands are executed, or not performing
2. indivisible transaction is a logical unit of work, while performing concurrent operations on the database system, the transaction is the smallest control unit
3. a scene for multi-user operation system database, such as banks, insurance companies and securities trading systems, etc.
4. Adoption of the integrity of the transaction in order to ensure data consistency

Features ACID transactions
Atomicity (Atomicity):

1. A transaction is a complete operation, each element of the transaction is (atoms) inseparable
all elements 2. The transaction must be committed or rolled back as a whole
3. If any element of the transaction fails, the whole transaction fails

Consistency (Consistency):

When the service is completed, the data must be in a consistent state: Before the beginning of the transaction, the data stored in the database in a consistent state; in the ongoing transaction, data may be in an inconsistent state; When the transaction is completed successfully, the data must have been back again known consistent state

Isolation (Isolation):

1. All concurrent transactions modify the data are isolated from each other, indicating that the transaction must be independent, it should not in any way affect or depend on other matters
2. The transaction data can be used to modify the same data in another transaction access the data after the end of the transaction to access the data before you begin, or use the same data in another

Persistent (Durability):

1. The transaction durability means that regardless of whether the system is a failure, the result of the transaction are permanent
2. Once the transaction is committed, the effect of the transaction will be permanently retained in the database

Operation of its services

1. Default MySQL transaction is automatically filed in the case when the sql statement submitted to the transaction will be automatically submitted

2. Manual control of the affairs of the method:

① Transaction command control
② use set transaction mode settings

3. Transaction command control transactions:

①begin: start a transaction
②commit: commit a transaction
②rollback: rollback a transaction

4. Use the set control commands:

①set autocommit = 0: Disable automatic submission
②set autocommit = 1: enable auto-commit


Storage Engine Concepts

1.MySQL data in a variety of different technologies stored in the file, each technology uses a different storage mechanism, indexing techniques, lock level and ultimately provide different functions and capabilities of these different technologies and supporting functions called storage engine in MySQL
2. MySQL storage engine is stored way data is stored in the file system or storage format
3. MySQL currently two commonly used storage engine:

MyISAM(适合读)
InnoDB(适合写)

4.MySQL storage engine MySQL database server components responsible for performing the actual data I / O operations for the database
5. One of the major advantages of the use of special storage engine is to provide only the desired specific characteristics of the application, the database system overhead smaller, more potent and higher performance database
6.MySQL system, is stored on the file system of the engine. Saved to the engine will be transferred to the memory before the data in the data file, after the storage format for storage in accordance with the respective storage engine

MyISAM Introduction

1.MyISAM storage engine is MySQ relational database system before the default storage engine version 5.5, the predecessor of the ISAM
2.ISAM is a well-defined and time-tested form of data management in the design to take into account the number of times the database is much larger than the update query
3.SAM features:

①ISAM speed read operation is performed quickly,
② it does not support transaction processing
③ and do not take up a lot of memory and storage resources
④ can not fault tolerant

Three files:

表定义文件
表数据存储文件
表索引文件

Examples of suitable MyISAM production scenarios:

1 do not need to support business transactions
2. General unilaterally read more data services, unilateral or more write data traffic
3.MyISAM storage engine scene data reading and writing are frequently unsuitable
4. Read concurrent write access to the relatively low traffic
5. the relatively small traffic data modification
6. the data service request is not very high consistency service
7. relatively poor hardware resources of the server

InnoDB features introduced

1. Support Services: Support four transaction isolation level
2. row-level locking, but will still be a full table scan table-level locking
3. write blocking associated with the transaction isolation level
4. Has a very efficient caching feature: can cache index, data can be cached
5. table primary key stored in a cluster
6. the support partition, table space, similar to the oracle database
7. support foreign key constraints, do not support the full-text index before 5.5, version 5.5 supports full-text indexing later
8. hardware resources requirements still relatively high occasions

InnoDB applicable production scene analysis

1. The need to support business transactions
2. row-level locking has a good ability to adapt to high concurrency, but need to make sure that the query is done by index
3. Operational data update more frequently scenarios, such as: forums, microblogging and other
4. It requires a high consistency of business data, such as: banking
5. hardware larger memory, better use Innodb caching capabilities to improve memory utilization, reduce disk IO pressure

Configuring Storage Engine

1. After selecting the appropriate storage engine in the enterprise, you can modify the
2. Modify the steps of:

See ① configurable database storage engine
② Display storage engine being used
③ storage engine configured for the selected type

3. Use the show engines view the system supported storage engines see table storage engine used

Method 1: show table status from the library name where name = 'name;
Method 2: show create table table

Guess you like

Origin blog.51cto.com/14464303/2462239