First, what is the storage engine?
Tables created in MySQL = = Folder
Tables created in the Library = = "File
In real life, the files we use to store data should have different types: for example, TXT type for storing text, Excel for storing tables, PNG for images, and so on.
Tables in the database should also have different types, table types do not, back to the MySQL different access mechanisms, table type is also known as the storage engine.
How does the storage engine store the data? How to index stored data and how to update, query data, and other techniques to implement the method, because in the relational database
Data storage is stored as a table, so the storage engine can also be called a table type (that is, the type that stores and operates this table)
There is only one storage engine in a database such as Oracle and SQL Server, and all data storage management mechanisms are the same. and MySQL
The database provides a variety of storage engines. Users can choose different storage engines for their data tables according to different requirements, and users can also
Own the need to write your own storage engine.
Components such as SQL parser, SQL optimizer, buffer pool, storage engine, and so on are present in each database, but not every database has so many storage engines. MySQL's plug-in storage engine allows developers of the storage engine layer to design the storage tier they want, for example, some applications need to meet the requirements of the transaction, some applications do not need to have such strong requirements for the transaction, some want the data to be persisted, and some only want to put in memory, temporarily and quickly to provide data query.
Two: the storage engine supported by MySQL.
MariaDB [(None)]> show Engines\g #查看所有支持的存储引擎MariaDB [(none)]> show variables like ' storage_engine% '; View the storage engine in use
Description of the MySQL storage engine:
The #InnoDB storage engine supports transactions and is designed primarily for online transaction processing (OLTP) applications. It features a row lock design, supports foreign keys, and supports non-locking reads like Oracle, where the default read operation does not generate locks. Starting with MySQL version 5.5.8 is the default storage engine. The InnoDB storage engine places the data in a logical table space, which is managed by the InnoDB storage engine itself like a black box. Starting with MySQL 4.1 (including 4.1), you can store the table for each InnoDB storage engine in a separate IBD file. In addition, the InnoDB storage engine supports the use of a bare device (row disk) to establish its tablespace. InnoDB achieves high concurrency by using multi-version concurrency control (MVCC), and implements 4 isolation levels for the SQL standard, default to the repeatable level, and uses a strategy called Netx-key locking to avoid the generation of Phantom Read (Phantom) phenomena 。 In addition to this, the InnoDB storage engine provides high performance and high-availability features such as insert buffer, two write (double write), Adaptive Hash Index (Adaptive hash indexes), pre-read (read ahead), and more. For storage of data in tables, the InnoDB storage engine uses aggregation (clustered), each table is stored in the order of the primary key, and if no primary key is explicitly specified when the table is defined, the InnoDB storage engine generates a 6-byte ROWID for each row as the primary key. The InnoDB storage engine is the most commonly used engine for MySQL databases, and successful applications from companies such as Facebook, Google, and Yahoo! have proven that the InnoDB storage engine is highly available, high performance, and highly scalable. The mastery and understanding of its underlying implementation also requires time and technology to accumulate. If you want to learn more about how the InnoDB storage engine works, implemented, and applied, you can refer to the "MySQL Insider: InnoDB Storage Engine" book. The #MyISAM storage engine does not support transactions, table lock design, and full-text indexing, primarily for OLAP database applications, which are the default storage engine (except for Windows versions) before MySQL 5.5.8. A big difference between a database system and a file system is the support for transactions, which are not supported by the MyISAM storage engine. It is not difficult to understand the fundamental. Does the user need a transaction in all applications? In the Data warehouse, if there is no ETL Do these operations simply require transactional support through a report query? In addition, another differentiator of the MyISAM storage engine is that its buffer pool caches only (cache) index files and does not cache data files, which is not the same as most databases. #NDB Storage Engine 2003, MySQL AB acquired the NDB storage engine from Sony Ericsson Corporation. The NDB storage engine is a clustered storage engine, similar to Oracle's RAC cluster, but unlike the share everything structure of the Oracle RAC, its structure is a cluster architecture that share nothing, thus providing a higher level of high availability. The NDB storage engine is characterized by the fact that the data is all in memory (starting with version 5.1, non-indexed data can be placed on disk), so the primary key lookup (primary key lookups) is extremely fast and can be added online NDB data node In order to improve database performance linearly. Thus, the NDB storage engine is a highly available, high-performance, highly scalable database cluster system, which is also a database application type for OLTP. #Memory Storage engine as its name, the data in the memory storage engine is stored in RAM, the database restarts or crashes, and the data in the table disappears. It is ideal for staging tables that store temporary data in an OLTP database application or as a dimension table for the Data warehouse in an OLAP database application. The memory storage engine uses a hash index by default instead of a B + tree index that is usually familiar. #Infobright Storage Engine third-party storage engine. It is characterized by columns rather than rows, making it ideal for OLAP database applications. Its official website is http://www.infobright.org/, which has a number of successful data warehousing cases to analyze. #NTSE Storage Engine NetEase has developed a storage engine for its internal use. The current version does not support transactions, but provides features such as compression, row-level caching, and, in the near future, memory-oriented transaction support. #BLACKHOLE黑洞存储引擎 that can be applied to the distribution Master library in primary and standby replication. The MySQL database also has many other storage engines, which are just some of the most commonly used engines. If you like, you can write your own engine, this is the ability of open source to us, but also the charm of open source.
Three: Using the storage engine
Method 1: Specify when the table is built
MariaDB [db1]> CREATE TABLE innodb_t1 (ID int,name char) engine=innodb; MariaDB [db1]> CREATE TABLE innodb_t2 (id int) Engine=innodb; MariaDB [db1]> Show create TABLE innodb_t1; MariaDB [db1]> Show create TABLE innodb_t2;
Method 2: Specify the default storage engine in the configuration file
/etc/my.cnf[mysqld]default-storage-engine=innodbinnodb_file_per_table=1
View:
[Email protected] db1]# cd/var/lib/mysql/db1/[[email protected] db1]# lsdb.opt innodb_t1.frm innodb_t1.ibd innodb_t2.frm innodb_t2.ibd
Practice
Create four tables, using the Innodb,myisam,memory,blackhole storage engine, for inserting data tests.
MariaDB [db1]> CREATE TABLE t1 (id int) Engine=innodb; MariaDB [db1]> CREATE TABLE t2 (id int) Engine=myisam; MariaDB [db1]> CREATE TABLE t3 (id int) engine=memory; MariaDB [db1]> CREATE table t4 (id int) engine=blackhole; MariaDB [db1]> quit[[email protected] db1]# ls/var/lib/mysql/db1/#发现后两种存储引擎只有表结构, no data db.opt t1.frm t1.ibd T2. MYD T2. MYI t2.frm t3.frm t4.frm#memory, after restarting MySQL or restarting the machine, the data in the table is emptied #blackhole, inserting any data into the table is equivalent to throwing into a black hole, the table will never save records
Mysql = = "Storage Engine"