Home Database Mysql Tutorial 辛星解读mysql中的MyISAM引擎_MySQL

辛星解读mysql中的MyISAM引擎_MySQL

Jun 01, 2016 pm 01:02 PM
engine

很多以前的教科书上都是写的MyISAM是mysql的默认存储引擎,其实自从mysql5.5开始,默认存储引擎就已经改变成为InnoDB了,由于InnoDB在很多方面有着不可替代的功能,因此,很多人喜欢研究InnoDB也在情理之中,我也很喜欢InnoDB。但是呢,对于MyISAM,就跟着辛星辛博士来认识一下吧。

第一点就是MyISAM不支持事务和外键,也正是基于这一点,很多人不喜欢MyISAM。但是MyISAM并不着急改变自己,因为这个引擎的重心是性能,而不是功能,不可否认,MyISAM的性能是非常卓越的,尤其在读数据上面。

第二点就是它的文件格式,一个MyISAM表通常分为三部分,第一部分是xxx.frm,这个文件用于存储表的定义,我们使用alter table的时候就会修改这个数据,因此使用alter table的速度是比较快的,第二部分是后缀名是myd的文件,其实这里的d是data的首字母,用于存放MyISAM的数据文件,第三部分是后缀名是myi的文件,这里的i是index的首字母,用于存放MyISAM的索引文件。默认情况下数据文件和索引文件是放在同一个目录下的,但是我们也可以放在不同的目录来获得更高的速度。

第三点就是MyISAM支持三种不同的存储格式,它们分别是静态格式、动态格式和压缩格式,这里注意压缩格式只能使用myisampack工具来创建。先说静态格式,它也是MyISAM的默认存储格式,当我们的表中不包含变量长度列比如varchar等数据类型时,它会自动使用这个格式,每一行都会选用固定的字节数存储。静态格式的优点就是查找速度非常快,容易缓存,容易修复(我在前面讲数据碎片的时候提到过用optimize table来修复表),缺点就是占据的磁盘空间要多一些。然后说动态格式,动态格式较为复杂一些,因为每行都有一个表明行有多长的列。每个记录仅仅需要必需大小的空间,如果一个记录变大的话,它就按照需要被分开成为多片,造成记录碎片。比如当我们用扩展长度的信息更新数据,该行就会产生碎片。因为动态的原因,也就更容易产生碎片,所以我们往往需要多次的优化表。

       对于压缩表,我们应该先建立一个表,然后使用myisampack来压缩,压缩之后的表会占用较小的磁盘空间,这样会最小化磁盘的使用,而且它是每个记录单独压缩的,所以访问的时候的开销还是蛮小的,它还会修改相应的我们的数据类型。比如一个列的值在-128到127之间,但是我们使用了int来存储,那么它会自动转化为tinyint来存储。如果一个列只有一组很小的可能的值,则列的类型被转化为ENUM。
Copy after login

那么很多人可能想说我们实例操作一下表的压缩吧,好的,辛星童鞋绝对满足大家的要求,我们来实例操作一下,不过必须说明的是,对于太小的表,是不会去压缩的,比如下面的两个例子:

C:\Users\Administrator>myisampack user.MYI
user.MYI is too small to compress

C:\Users\Administrator>myisampack db.MYI
db.MYI is too small to compress
Copy after login

那我们找个稍微大一点的表来做实验:

C:\Users\Administrator>myisampack help_keyword.MYI
Compressing help_keyword.MYD: (483 records)
- Calculating statistics
- Compressing file
95.15%
Remember to run myisamchk -rq on compressed tables
Copy after login


此时,表的压缩就完成了,可以看出我们的表中原来存放了483条记录,而且它还提示我们使用myisamchm来解压缩。

第四点问题就是锁定和并发,MyISAM在加锁的时候会对整张表都加锁,这也是MyISAM广为诟病的一点,但是在处理并发上,在读取数据的时候,所有的表上都可以获得共享锁,也就是每个连接会互不干扰,而在写数据的时候,会获得排他锁,会对整个表进行加锁,其他的请求包括读和写都必须处于等待状态。

第五点就提到了表的修复,这一点也是MyISAM的方便的地方,它可以使用【check table 表名】来检测表,还可以使用【repair table 表名】来修复表,当然还可以使用optimize来优化表,比如去除数据碎片等等。

第六点也是比较重要的一点,那就是,MyISAM是支持全文索引的,但是InnoDB不支持,这也是MyISAM少数的几个比InnoDB功能还多的功能,但是目前的MyISAM貌似还是不支持中文,不过我们可以使用第三方技术来弥补这一点。

这一次就先写到这里吧,期待您的关注。

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

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)

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

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.

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

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

Solve engine problems when SAS connects to Oracle database Solve engine problems when SAS connects to Oracle database Mar 08, 2024 am 10:12 AM

To solve engine problems when SAS connects to Oracle database, specific code examples are required. When using SAS software for data analysis, it is often necessary to connect to the database to obtain data for analysis and processing. Among them, connecting to the Oracle database is a relatively common operation. However, sometimes engine problems occur when connecting to the Oracle database, causing the connection to fail or not operate normally. This article will introduce how to solve engine problems when connecting to Oracle database in SAS software, and provide specific code

How to use PHP web template engine and FAQs How to use PHP web template engine and FAQs Jun 08, 2023 pm 12:23 PM

With the continuous development of Internet technology, web template engines have become an indispensable part of website development. PHP web page template engine is one of the commonly used web page template engines. This article will introduce how to use the PHP web template engine and answer frequently asked questions. 1. What is PHP web template engine? PHP web template engine is a technology that separates web design from business logic. Using a template engine can separate the display and logical processing of web pages, making the code clean, clear and easy to maintain. PHP web template engine and original

Father of Gmail: With ChatGPT, search engines won't survive more than two years Father of Gmail: With ChatGPT, search engines won't survive more than two years Apr 14, 2023 pm 01:22 PM

From the day ChatGPT was born, Microsoft should feel lucky. Apart from being glad that the $1 billion I invested a few years ago was not in vain. More importantly, ChatGPT is a friendly force, not an opponent. The mood of other major technology companies is very complicated, especially Microsoft's old rival Google. Paul Buchheit, a veteran Google employee and one of the creators of Gmail, recently said that artificial intelligence chatbots like ChatGPT will destroy Google, just like the search engine completely wiped out the yellow pages phone book. As for the time, it is only a matter of one or two years. Buchheit tweeted on Wednesday: "It may only take a year or two for Google to be completely disrupted. AI will wipe out the search engine results page, even after

Subvert history! 'ChatGPT search engine' released, Microsoft's market value soared 545 billion overnight Subvert history! 'ChatGPT search engine' released, Microsoft's market value soared 545 billion overnight Apr 12, 2023 am 11:10 AM

For two days in a row, we were witnessing history. The major companies in Silicon Valley are already at war with each other, and the search engine war triggered by ChatGPT is about to break out. The day before, Google released its next-generation conversational AI system Bard, followed closely by Microsoft's official announcement of new versions of Bing and Edge the next day. Now, the new Bing can be experienced on Edge! Although the functions are still relatively limited. Microsoft's market value also rose by more than 80 billion U.S. dollars (approximately 545 billion yuan) overnight, reaching a five-month high. Another giant, Google, also rose by more than 4.6%, with its latest total market value of US$1.38 trillion, a new high in four months. ChatGPT search is officially born! Early this morning Beijing time, Microsoft held a press conference in Redmond, Washington.

See all articles