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引擎一样,都是页级锁定。

MySQLBLOBshavelimits:TINYBLOB(255bytes),BLOB(65,535bytes),MEDIUMBLOB(16,777,215bytes),andLONGBLOB(4,294,967,295bytes).TouseBLOBseffectively:1)ConsiderperformanceimpactsandstorelargeBLOBsexternally;2)Managebackupsandreplicationcarefully;3)Usepathsinst

The best tools and technologies for automating the creation of users in MySQL include: 1. MySQLWorkbench, suitable for small to medium-sized environments, easy to use but high resource consumption; 2. Ansible, suitable for multi-server environments, simple but steep learning curve; 3. Custom Python scripts, flexible but need to ensure script security; 4. Puppet and Chef, suitable for large-scale environments, complex but scalable. Scale, learning curve and integration needs should be considered when choosing.

Yes,youcansearchinsideaBLOBinMySQLusingspecifictechniques.1)ConverttheBLOBtoaUTF-8stringwithCONVERTfunctionandsearchusingLIKE.2)ForcompressedBLOBs,useUNCOMPRESSbeforeconversion.3)Considerperformanceimpactsanddataencoding.4)Forcomplexdata,externalproc

MySQLoffersvariousstringdatatypes:1)CHARforfixed-lengthstrings,idealforconsistentlengthdatalikecountrycodes;2)VARCHARforvariable-lengthstrings,suitableforfieldslikenames;3)TEXTtypesforlargertext,goodforblogpostsbutcanimpactperformance;4)BINARYandVARB

TomasterMySQLBLOBs,followthesesteps:1)ChoosetheappropriateBLOBtype(TINYBLOB,BLOB,MEDIUMBLOB,LONGBLOB)basedondatasize.2)InsertdatausingLOAD_FILEforefficiency.3)Storefilereferencesinsteadoffilestoimproveperformance.4)UseDUMPFILEtoretrieveandsaveBLOBsco

BlobdatatypesinmysqlareusedforvoringLargebinarydatalikeImagesoraudio.1) Useblobtypes (tinyblobtolongblob) Basedondatasizeneeds. 2) Storeblobsin Perplate Petooptimize Performance.3) ConsidersxterNal Storage Forel Blob Romana DatabasesizerIndimprovebackupupe

ToadduserstoMySQLfromthecommandline,loginasroot,thenuseCREATEUSER'username'@'host'IDENTIFIEDBY'password';tocreateanewuser.GrantpermissionswithGRANTALLPRIVILEGESONdatabase.*TO'username'@'host';anduseFLUSHPRIVILEGES;toapplychanges.Alwaysusestrongpasswo

MySQLofferseightstringdatatypes:CHAR,VARCHAR,BINARY,VARBINARY,BLOB,TEXT,ENUM,andSET.1)CHARisfixed-length,idealforconsistentdatalikecountrycodes.2)VARCHARisvariable-length,efficientforvaryingdatalikenames.3)BINARYandVARBINARYstorebinarydata,similartoC


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

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

WebStorm Mac version
Useful JavaScript development tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

SublimeText3 Chinese version
Chinese version, very easy to use
