Heim > Datenbank > MySQL-Tutorial > Hauptteil

mysql存储引擎(二)_MySQL

WBOY
Freigeben: 2016-06-08 08:50:36
Original
888 Leute haben es durchsucht

mysql存储引擎(二)


mysql存储引擎二 MEMORY MERGE BerkeleyDB存储引擎

MEMORY

MEMORY存储引擎通过采用内存中的内容来创建表。每个Memory表实际上和一个磁盘文件关联起来,文件名采用”表名.frm”的格式。Memory类型的表访问速度极快,因为数据源来自内存,所以数据库关闭时,内存中的数据就会发生丢失。默认使用Hash索引。

<code class="hljs asciidoc">mysql> create table memory_table( id int primary key, name varchar(20) )engine=memory;
Query OK, 0 rows affected (0.02 sec)

mysql> insert into memory_table(id,name) values(2,&#39;frank&#39;);
Query OK, 1 row affected (0.00 sec)

mysql> select * from memory_table;
+----+-----------+
| id | name      |
+----+-----------+
|  1 | frankstar |
|  2 | frank     |
+----+-----------+
2 rows in set (0.00 sec)

mysql> show table status like &#39;memory_table&#39; \G;
*************************** 1. row ***************************
           Name: memory_table
         Engine: MEMORY
        Version: 10
     Row_format: Fixed
           Rows: 2
 Avg_row_length: 66
    Data_length: 127008
Max_data_length: 12582900
   Index_length: 126992
      Data_free: 0
 Auto_increment: NULL
    Create_time: 2016-05-09 22:23:47
    Update_time: NULL
     Check_time: NULL
      Collation: utf8_bin
       Checksum: NULL
 Create_options:
        Comment:
1 row in set (0.00 sec)

ERROR:
No query specified

mysql> show index from memory_table \G;
*************************** 1. row ***************************
        Table: memory_table
   Non_unique: 0
     Key_name: PRIMARY
 Seq_in_index: 1
  Column_name: id
    Collation: NULL
  Cardinality: 2
     Sub_part: NULL
       Packed: NULL
         Null:
   Index_type: HASH
      Comment:
Index_comment:
1 row in set (0.00 sec)

ERROR:
No query specified
</code>
Nach dem Login kopieren

memory表的内存储存在内存中,如果表的数据很大,那么服务器将会自动将其转换为磁盘表,阀值由temp_table_size系统变量来确定。每个memory表的容量由max_heap_table_size变量的值控制。默认16MB。<br /> 主要用于数据内容变化不频繁的代码表及访问速度要求较高、数据量不大的场合,同时需要考虑更新操作数据不回写入到磁盘文件中。

MERGE

它实际上是一组myisam表的组合,将一组结构相同的MyISAM表组合在一起,MERGE表本身没有数据,对于该类型表的插入操作,是通过INSERT_METHOD定义完成的,取值为LAST或者为FIRST,FIRST意味着数据增加到组合表中的第一个myisam表中,同理LAST意味着添加到最后一个表中。所以MERGE表的文件有2个,一个是.frm文件,用于存放数据,还有一个MRG文件,用于存放MERGE表的名称,包括其组成表。

如下:

<code class="hljs asciidoc"><code class="hljs haml">mysql> create table myisam_table1(
    -> id int primary key,
    -> data datetime
    -> )engine=myisam;
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(
    -> id int primary key,
    -> data datetime
    -> )engine=merge union=(myisam_table1,myisam_table2) insert_method=first;
Query OK, 0 rows affected (0.01 sec)</code></code>
Nach dem Login kopieren

<code class="hljs haml">向2个字表分别添加数据,如下:

<code class="hljs asciidoc"><code class="hljs haml"><code class="hljs cs">mysql> insert into myisam_table1 values(1,&#39;2016-5-7&#39;);
Query OK, 1 row affected (0.00 sec)

mysql> insert into myisam_table1 values(2,&#39;2016-5-6&#39;);
Query OK, 1 row affected (0.00 sec)

mysql> insert into myisam_table2 values(1,&#39;2016-5-7&#39;);
Query OK, 1 row affected (0.00 sec)

mysql> insert into myisam_table2 values(2,&#39;2016-5-6&#39;);
Query OK, 1 row affected (0.00 sec)
</code></code></code>
Nach dem Login kopieren

<code class="hljs haml"><code class="hljs cs">查询merge表,如下:

<code class="hljs asciidoc"><code class="hljs haml"><code class="hljs cs"><code class="hljs asciidoc">mysql> select * from table1_merge_table2;
+----+---------------------+
| id | data                |
+----+---------------------+
|  1 | 2016-05-07 00:00:00 |
|  2 | 2016-05-06 00:00:00 |
|  1 | 2016-05-07 00:00:00 |
|  2 | 2016-05-06 00:00:00 |
+----+---------------------+
4 rows in set (0.01 sec)</code></code></code></code>
Nach dem Login kopieren

<code class="hljs haml"><code class="hljs cs"><code class="hljs asciidoc">向merge表中添加一条数据,如下:

<code class="hljs asciidoc"><code class="hljs haml"><code class="hljs cs"><code class="hljs asciidoc"><code class="hljs asciidoc">mysql> insert into table1_merge_table2 values(3,&#39;2016-5-8&#39;);
Query OK, 1 row affected (0.00 sec)

mysql> select * from table1_merge_table2;
+----+---------------------+
| id | data                |
+----+---------------------+
|  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 |
|  2 | 2016-05-06 00:00:00 |
+----+---------------------+
5 rows in set (0.00 sec)


mysql> select * from myisam_table1;
+----+---------------------+
| id | data                |
+----+---------------------+
|  1 | 2016-05-07 00:00:00 |
|  2 | 2016-05-06 00:00:00 |
|  3 | 2016-05-08 00:00:00 |
+----+---------------------+
3 rows in set (0.00 sec)

mysql> select * from myisam_table2;
+----+---------------------+
| id | data                |
+----+---------------------+
|  1 | 2016-05-07 00:00:00 |
|  2 | 2016-05-06 00:00:00 |
+----+---------------------+
2 rows in set (0.00 sec)</code></code></code></code></code>
Nach dem Login kopieren

<code class="hljs haml"><code class="hljs cs"><code class="hljs asciidoc"><code class="hljs asciidoc">INSERT_METHOD的指定起作用了,如果没有指定,那么当试图往Merge表中insert数据时,都会发生错误。通常使用merge表来透明的对多个表进行查询和更新。

<code class="hljs haml"><code class="hljs cs"><code class="hljs asciidoc"><code class="hljs asciidoc">BerkeleyDB存储引擎

<code class="hljs haml"><code class="hljs cs"><code class="hljs asciidoc"><code class="hljs asciidoc">简称BDB,创建该类型的表时,会有2个数据文件,一个.frm文件存储表元数据,另一个.db文件存储数据和索引文件,类似innodb。它的实现事务安全有redo日志。在每次启动的时候,都会做一次检查操作,将所有的redo日志清空。它和Memory引擎一样,都是页级锁定。

Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!