mysql存储引擎(二)
mysql存储引擎(二) mysql存储引擎二 MEMORY MERGE BerkeleyDB存储引擎 MEMORY MEMORY存储引擎通过采用内存中的内容来创建表。每个Memory表实际上和一个磁盘文件关联起来,文件名采用”表名.frm”的格式。Memory类型的表访问速度极快,因为数据源来自内存,
mysql存储引擎(二)
-
-
- mysql存储引擎二
- MEMORY
- MERGE
- BerkeleyDB存储引擎
- mysql存储引擎二
-
MEMORY
MEMORY存储引擎通过采用内存中的内容来创建表。每个Memory表实际上和一个磁盘文件关联起来,文件名采用”表名.frm”的格式。Memory类型的表访问速度极快,因为数据源来自内存,所以数据库关闭时,内存中的数据就会发生丢失。默认使用Hash索引。
<code class=" hljs asciidoc">mysql> create table memory<span class="hljs-emphasis">_table( id int primary key, name varchar(20) )engine=memory; Query OK, 0 rows affected (0.02 sec) </span>mysql> insert into memory<span class="hljs-emphasis">_table(id,name) values(2,'frank'); Query OK, 1 row affected (0.00 sec) </span><span class="hljs-header">mysql> select * from memory_table; +----+-----------+</span> <span class="hljs-header">| id | name | +----+-----------+</span> | 1 | frankstar | <span class="hljs-header">| 2 | frank | +----+-----------+</span> 2 rows in set (0.00 sec) mysql> show table status like <span class="hljs-emphasis">'memory_table'</span> \G; <span class="hljs-bullet">*************************** </span>1. row *************************** <span class="hljs-code"> Name: memory_table</span> <span class="hljs-code"> Engine: MEMORY</span> <span class="hljs-code"> Version: 10</span> <span class="hljs-code"> Row_format: Fixed</span> <span class="hljs-code"> Rows: 2</span> <span class="hljs-code"> Avg_row_length: 66</span> <span class="hljs-code"> Data_length: 127008</span> Max<span class="hljs-emphasis">_data_</span>length: 12582900 <span class="hljs-code"> Index_length: 126992</span> <span class="hljs-code"> Data_free: 0</span> <span class="hljs-code"> Auto_increment: NULL</span> <span class="hljs-code"> Create_time: 2016-05-09 22:23:47</span> <span class="hljs-code"> Update_time: NULL</span> <span class="hljs-code"> Check_time: NULL</span> <span class="hljs-code"> Collation: utf8_bin</span> <span class="hljs-code"> Checksum: NULL</span> <span class="hljs-code"> Create_options:</span> <span class="hljs-code"> Comment:</span> 1 row in set (0.00 sec) ERROR: No query specified mysql> show index from memory<span class="hljs-emphasis">_table \G; *************************** 1. row *************************** Table: memory_</span>table <span class="hljs-code"> Non_unique: 0</span> <span class="hljs-code"> Key_name: PRIMARY</span> <span class="hljs-code"> Seq_in_index: 1</span> <span class="hljs-code"> Column_name: id</span> <span class="hljs-code"> Collation: NULL</span> <span class="hljs-code"> Cardinality: 2</span> <span class="hljs-code"> Sub_part: NULL</span> <span class="hljs-code"> Packed: NULL</span> <span class="hljs-code"> Null:</span> <span class="hljs-code"> Index_type: HASH</span> <span class="hljs-code"> Comment:</span> Index<span class="hljs-emphasis">_comment: 1 row in set (0.00 sec) </span>ERROR: No query specified </code>
memory表的内存储存在内存中,如果表的数据很大,那么服务器将会自动将其转换为磁盘表,阀值由temp_table_size系统变量来确定。每个memory表的容量由max_heap_table_size变量的值控制。默认16MB。
主要用于数据内容变化不频繁的代码表及访问速度要求较高、数据量不大的场合,同时需要考虑更新操作数据不回写入到磁盘文件中。
MERGE
它实际上是一组myisam表的组合,将一组结构相同的MyISAM表组合在一起,MERGE表本身没有数据,对于该类型表的插入操作,是通过INSERT_METHOD定义完成的,取值为LAST或者为FIRST,FIRST意味着数据增加到组合表中的第一个myisam表中,同理LAST意味着添加到最后一个表中。所以MERGE表的文件有2个,一个是.frm文件,用于存放数据,还有一个MRG文件,用于存放MERGE表的名称,包括其组成表。
如下:
<code class=" hljs haml">mysql> create table myisam_table1( -<span class="ruby">> id int primary key, </span> -<span class="ruby">> data datetime </span> -<span class="ruby">> )engine=myisam; </span>Query OK, 0 rows affected (0.02 sec) create table myisam_table2( id int primary key, data datetime )engine=myisam; Query OK, 0 rows affected (0.01 sec) mysql> create table table1_merge_table2( -<span class="ruby">> id int primary key, </span> -<span class="ruby">> data datetime </span> -<span class="ruby">> )engine=merge union=(myisam_table1,myisam_table2) insert_method=first; </span>Query OK, 0 rows affected (0.01 sec)</code>
向2个字表分别添加数据,如下:
<code class=" hljs cs">mysql> insert <span class="hljs-keyword">into</span> myisam_table1 values(<span class="hljs-number">1</span>,<span class="hljs-string">'2016-5-7'</span>); Query OK, <span class="hljs-number">1</span> row affected (<span class="hljs-number">0.00</span> sec) mysql> insert <span class="hljs-keyword">into</span> myisam_table1 values(<span class="hljs-number">2</span>,<span class="hljs-string">'2016-5-6'</span>); Query OK, <span class="hljs-number">1</span> row affected (<span class="hljs-number">0.00</span> sec) mysql> insert <span class="hljs-keyword">into</span> myisam_table2 values(<span class="hljs-number">1</span>,<span class="hljs-string">'2016-5-7'</span>); Query OK, <span class="hljs-number">1</span> row affected (<span class="hljs-number">0.00</span> sec) mysql> insert <span class="hljs-keyword">into</span> myisam_table2 values(<span class="hljs-number">2</span>,<span class="hljs-string">'2016-5-6'</span>); Query OK, <span class="hljs-number">1</span> row affected (<span class="hljs-number">0.00</span> sec) </code>
查询merge表,如下:
<code class=" hljs asciidoc"><span class="hljs-header">mysql> select * from table1_merge_table2; +----+---------------------+</span> <span class="hljs-header">| id | data | +----+---------------------+</span> | 1 | 2016-05-07 00:00:00 | | 2 | 2016-05-06 00:00:00 | | 1 | 2016-05-07 00:00:00 | <span class="hljs-header">| 2 | 2016-05-06 00:00:00 | +----+---------------------+</span> 4 rows in set (0.01 sec)</code>
向merge表中添加一条数据,如下:
<code class=" hljs asciidoc">mysql> insert into table1<span class="hljs-emphasis">_merge_</span>table2 values(3,<span class="hljs-emphasis">'2016-5-8'</span>); Query OK, 1 row affected (0.00 sec) <span class="hljs-header">mysql> select * from table1_merge_table2; +----+---------------------+</span> <span class="hljs-header">| id | data | +----+---------------------+</span> | 1 | 2016-05-07 00:00:00 | | 2 | 2016-05-06 00:00:00 | | 3 | 2016-05-08 00:00:00 | | 1 | 2016-05-07 00:00:00 | <span class="hljs-header">| 2 | 2016-05-06 00:00:00 | +----+---------------------+</span> 5 rows in set (0.00 sec) <span class="hljs-header">mysql> select * from myisam_table1; +----+---------------------+</span> <span class="hljs-header">| id | data | +----+---------------------+</span> | 1 | 2016-05-07 00:00:00 | | 2 | 2016-05-06 00:00:00 | <span class="hljs-header">| 3 | 2016-05-08 00:00:00 | +----+---------------------+</span> 3 rows in set (0.00 sec) <span class="hljs-header">mysql> select * from myisam_table2; +----+---------------------+</span> <span class="hljs-header">| id | data | +----+---------------------+</span> | 1 | 2016-05-07 00:00:00 | <span class="hljs-header">| 2 | 2016-05-06 00:00:00 | +----+---------------------+</span> 2 rows in set (0.00 sec)</code>
INSERT_METHOD的指定起作用了,如果没有指定,那么当试图往Merge表中insert数据时,都会发生错误。通常使用merge表来透明的对多个表进行查询和更新。
BerkeleyDB存储引擎
简称BDB,创建该类型的表时,会有2个数据文件,一个.frm文件存储表元数据,另一个.db文件存储数据和索引文件,类似innodb。它的实现事务安全有redo日志。在每次启动的时候,都会做一次检查操作,将所有的redo日志清空。它和Memory引擎一样,都是页级锁定。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

The main role of MySQL in web applications is to store and manage data. 1.MySQL efficiently processes user information, product catalogs, transaction records and other data. 2. Through SQL query, developers can extract information from the database to generate dynamic content. 3.MySQL works based on the client-server model to ensure acceptable query speed.

The process of starting MySQL in Docker consists of the following steps: Pull the MySQL image to create and start the container, set the root user password, and map the port verification connection Create the database and the user grants all permissions to the database

Laravel is a PHP framework for easy building of web applications. It provides a range of powerful features including: Installation: Install the Laravel CLI globally with Composer and create applications in the project directory. Routing: Define the relationship between the URL and the handler in routes/web.php. View: Create a view in resources/views to render the application's interface. Database Integration: Provides out-of-the-box integration with databases such as MySQL and uses migration to create and modify tables. Model and Controller: The model represents the database entity and the controller processes HTTP requests.

I encountered a tricky problem when developing a small application: the need to quickly integrate a lightweight database operation library. After trying multiple libraries, I found that they either have too much functionality or are not very compatible. Eventually, I found minii/db, a simplified version based on Yii2 that solved my problem perfectly.

The key to installing MySQL elegantly is to add the official MySQL repository. The specific steps are as follows: Download the MySQL official GPG key to prevent phishing attacks. Add MySQL repository file: rpm -Uvh https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm Update yum repository cache: yum update installation MySQL: yum install mysql-server startup MySQL service: systemctl start mysqld set up booting

Installing MySQL on CentOS involves the following steps: Adding the appropriate MySQL yum source. Execute the yum install mysql-server command to install the MySQL server. Use the mysql_secure_installation command to make security settings, such as setting the root user password. Customize the MySQL configuration file as needed. Tune MySQL parameters and optimize databases for performance.

Article summary: This article provides detailed step-by-step instructions to guide readers on how to easily install the Laravel framework. Laravel is a powerful PHP framework that speeds up the development process of web applications. This tutorial covers the installation process from system requirements to configuring databases and setting up routing. By following these steps, readers can quickly and efficiently lay a solid foundation for their Laravel project.

MySQL and phpMyAdmin are powerful database management tools. 1) MySQL is used to create databases and tables, and to execute DML and SQL queries. 2) phpMyAdmin provides an intuitive interface for database management, table structure management, data operations and user permission management.
