Table of Contents
概述
MyISAM
InnoDB
MEMORY
MERGE
总结
Home Database Mysql Tutorial (5)mysql常用存储引擎_MySQL

(5)mysql常用存储引擎_MySQL

Jun 01, 2016 pm 01:00 PM
Commonly used engine

概述

??mysql5.5之前默认存储引擎是MyISAM,5.5之后改为InnoDB。若要修改默认引擎,可以修改配置文件中的default-storage-engine。可以通过show engines来查看当前数据库支持的引擎。使用select engine from information_schema.engines where transactions = 'yes';来查看哪些引擎支持事务。在创建表到时候通过engine=...或type=...来指定所要使用到引擎。

MyISAM

它不支持事务,也不支持外键,其优势是访问的速度快,对事务完整性没有要求的或者以select/insert为主的应用基本上可以使用这个引擎来创建表。

每个MyISAM在磁盘上都有3个文件,其文件名都与表名相同,但扩展名是:

.frm(表定义) .MYD(MYDate:存储数据) .MYI(MYIndex:存储索引) .MYD文件和.MYI文件可以放置在不同的目录中,通过 data directory 和index directory语句指定。 MyISAM类型的表可能会损坏,可以使用CHECK TABLE语句来检查MyISAM表的健康,并用REPAIR TABLE语句修复一个损坏到MyISAM表。

MyISAM支持3种不同的存储格式:

静态(固定长度)表 动态表 压缩表

??在静态表中,如果需要保存的内容后面本来就带有空格,那么在返回结果的时候会去掉公共的。
??在动态表中,记录不固定,优点是占用空间相对比较少,缺点是频繁的更新和删除记录会产生碎片,需要定期执行optimize table 来改善性能。
??在压缩表中,由myisampack工具创建,占据非常小的磁盘空间。因为每个记录都被单独压缩的。

InnoDB

InnoDB支持事务安全,对比MyISAM引擎,InnoDB写的效率差一些,并且会占据更多的磁盘空间。 InnoDB自动增长列可以手工插入,但是插入的值是空或者0,则实际插入的将是自动增长后的值。可以使用last_insert_id()查询当前线程最后插入记录使用的值。可以通过alert table *** auto_increment=n;语句强制设置自动增长值。 对于InnoDB表,自动增长列必须是索引。如果是组合索引,也必须是组合索引的第一列,但是对于MyISAM表,自动增长列可以是组合索引的其他列,这样插入记录后,自动增长列是按照组合索引到前面几列排序后递增的。 MySQL支持外键的存储引擎只有InnoDB,在创建外键的时候,父表必须有对应的索引,子表在创建外键的时候也会自动创建对应的索引。在创建索引的时候,可以指定在删除、更新父表时,对子表进行的相应操作,包括restrict、cascade、set null和no action。其中restrict和no action相同,是指限制在子表有关联的情况下,父表不能更新;casecade表示父表在更新或删除时,更新或者删除子表对应的记录;set null 则表示父表在更新或者删除的时候,子表对应的字段被set null。当某个表被其它表创建了外键参照,那么该表对应的索引或主键被禁止删除。可以使用set foreign_key_checks=0;临时关闭外键约束,set foreign_key_checks=1;打开约束。

InnoDB存储表和索引有如下两种方式:

使用共享表空间存储。 使用多表空间存储。

MEMORY

memory使用存在内存中的内容来创建表。每个MEMORY表实际对应一个磁盘文件,格式是.frm。MEMORY类型的表访问非常快,因为它到数据是放在内存中的,并且默认使用HASH索引,但是一旦服务器关闭,表中的数据就会丢失,但表还会继续存在。 每个MEMORY表中放置到数据量的大小,受到max_heap_table_size系统变量的约束,这个系统变量的初始值是16M,同时在创建MEMORY表时可以使用MAX_ROWS子句来指定表中的最大行数。 memory主要用于那些内容变化不频繁的代码表,或作为统计操作的中间结果表。

MERGE

merge存储引擎是一组MyISAM表的组合,这些MyISAM表结构必须完全相同,MERGE表中并没有数据,对MERGE类型的表可以进行查询、更新、删除的操作,这些操作实际上是对内部的MyISAM表进行操作。 对于对MERGE表进行的插入操作,是根据INSERT_METHOD子句定义的插入的表,可以有3个不同的值,first和last值使得插入操作被相应的作用在第一个或最后一个表上,不定义这个子句或者为NO,表示不能对这个MERGE表进行插入操作。 可以对MERGE表进行drop操作,这个操作只是删除MERGE表的定义,对内部的表没有任何影响。 MERGE在磁盘上保留2个以MERGE表名开头文件:.frm文件存储表的定义;.MRG文件包含组合表的信息,包括MERGE表由哪些表组成,插入数据时的依据。可以通过修改.MRG文件来修改MERGE表,但是修改后要通过flush table刷新。 merge表与分区表的区别是:merge表不会智能的将记录写到对应的表中,而分区表可以的。

总结

仍一张表作为总结:
mysql常用存储引擎

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Learn the canvas framework and explain the commonly used canvas framework in detail Learn the canvas framework and explain the commonly used canvas framework in detail Jan 17, 2024 am 11:03 AM

Explore the Canvas framework: To understand what are the commonly used Canvas frameworks, specific code examples are required. Introduction: Canvas is a drawing API provided in HTML5, through which we can achieve rich graphics and animation effects. In order to improve the efficiency and convenience of drawing, many developers have developed different Canvas frameworks. This article will introduce some commonly used Canvas frameworks and provide specific code examples to help readers gain a deeper understanding of how to use these frameworks. 1. EaselJS framework Ea

Spring Annotation Revealed: Analysis of Common Annotations Spring Annotation Revealed: Analysis of Common Annotations Dec 30, 2023 am 11:28 AM

Spring is an open source framework that provides many annotations to simplify and enhance Java development. This article will explain commonly used Spring annotations in detail and provide specific code examples. @Autowired: Autowired @Autowired annotation can be used to automatically wire beans in the Spring container. When we use the @Autowired annotation where dependencies are required, Spring will find matching beans in the container and automatically inject them. The sample code is as follows: @Auto

Redmi G Pro 2024 See you on March 4th, with ice cooling and violent engine PC version support Redmi G Pro 2024 See you on March 4th, with ice cooling and violent engine PC version support Mar 02, 2024 pm 12:19 PM

Redmi officially announced today that the new Redmi GPro 2024 will be officially released on March 4. In other words, next week we will have the release of this exciting new product. RedmiGPro2024 makes its full debut as an e-sports flagship, deeply integrating the mobile phone industry capabilities into the notebook business, presenting 210W super performance release, and Redmi performance reaching a new high. Equipped with i9-14900HX processor and RTX4060 graphics card, it perfectly combines e-sports and creation to achieve dual evolution. From this point of view, the performance of this new product will be improved again, and the actual effect is exciting. It was mentioned in the official warm-up that the new Redmi G Pro 2024 brings the PC version of the violent engine. Mobile phone technology empowerment, three major factors lead

Super realistic rendering! Unreal Engine technology expert explains the global illumination system Lumen Super realistic rendering! Unreal Engine technology expert explains the global illumination system Lumen Apr 08, 2023 pm 10:21 PM

Real-time global illumination (Real-time GI) has always been the holy grail of computer graphics. Over the years, the industry has proposed various methods to solve this problem. Common methods include constraining the problem domain by utilizing certain assumptions, such as static geometry, a rough scene representation, or tracking rough probes, and interpolating lighting between the two. In Unreal Engine, the global illumination and reflection system Lumen technology was co-founded by Krzysztof Narkowicz and Daniel Wright. The goal was to build a solution that was different from its predecessors, capable of achieving uniform lighting and a baked-like lighting quality. Recently, at SIGGRAPH 2022, Krzysztof Narko

Actual test of NVIDIA AI game engine: real-time chat with NPC, Chinese is fluent Actual test of NVIDIA AI game engine: real-time chat with NPC, Chinese is fluent Mar 04, 2024 am 09:40 AM

The intelligent NPC created by Academician Huang in "Cyberpunk 2077" can already speak Chinese? Qubit's first-hand experience, witnessing NPCs conversing fluently in both Chinese and English, with natural expressions and movements, and matching mouth shapes... If there wasn't a screen in front of me, it would really feel like being there. . At this year's CES exhibition, Nvidia used its intelligent engine Avatar Cloud Engine (ACE) to make game NPCs "alive", which caused quite a shock. △The intelligent NPC displayed at CES uses ACE. The characters in the game can have realistic voice conversations with players, while showing vivid expressions and body movements without having to prepare a script in advance. At the time of its debut, there were Ubisoft, Tencent, NetEase, MiHoYo and other countries.

Engine landscape changes: Three-cylinder engines challenge the dominance of six-cylinders and eight-cylinders Engine landscape changes: Three-cylinder engines challenge the dominance of six-cylinders and eight-cylinders Oct 08, 2023 pm 10:57 PM

According to news on October 8, the U.S. auto market is undergoing a change under the hood. The previously beloved six-cylinder and eight-cylinder power engines are gradually losing their dominance, while three-cylinder engines are emerging. News on October 8 showed that the U.S. auto market is undergoing a change under the hood. The beloved six-cylinder and eight-cylinder power engines in the past are gradually losing their dominance, and the three-cylinder engine is beginning to emerge. In most people's minds, Americans love large-displacement models, and the "American big V8" has always been the Synonymous with American cars. However, according to data recently released by foreign media, the landscape of the U.S. auto market is undergoing tremendous changes, and the battle under the hood is intensifying. It is understood that before 2019, the United States

15 commonly used currency circle escape index technology analysis 15 commonly used currency circle escape index technology analysis Mar 03, 2025 pm 05:48 PM

In-depth analysis of the top 15 Bitcoin Escape Index: Market Outlook for 2025 This article deeply analyzes fifteen commonly used Bitcoin Escape Index, among which the Bitcoin Rhodl ratio, USDT current wealth management and altcoin seasonal index have reached the Escape Index in 2024, attracting market attention. How should investors deal with potential risks? Let us interpret these indicators one by one and explore reasonable response strategies. 1. Detailed explanation of key indicators AHR999 coin hoarding indicator: Created by ahr999, assisting Bitcoin fixed investment strategy. The current value is 1.21, which is in the wait-and-see range, so it is recommended to be cautious. Link to AHR999 Escape Top Indicator: A supplement to AHR999 Coin Hoarding Indicator, used to identify the top of the market. The current value is 2.48, this week

What are the commonly used encryption algorithms in PHP? What are the commonly used encryption algorithms in PHP? May 12, 2023 pm 06:51 PM

With the development of the Internet, data security has become a serious issue that we must pay attention to in our daily work. Encryption becomes especially important when it comes to sensitive personal information or business data. In PHP development, some encryption algorithms are widely used. Let's take a look at the encryption algorithms commonly used in PHP. 1. Base64 encoding Base64 encoding is often used to transmit binary data in web pages or emails, because web pages or emails can only transmit string type data and cannot directly transmit binary data. Base64 is a solution

See all articles