8.4 中文镜像

MySQL 8.4 参考手册 · 中文镜像

正文为中文,英文原文默认隐藏。点击任意中文段落即可展开 / 收起对应英文原文。

打开官方英文原文 ↗

译文由机器翻译生成,仅供理解参考;有疑问请以官方英文原文为准。

中文点击中文段落可显示 / 隐藏英文原文本页译文覆盖 99%

18.2 MyISAM 存储引擎18.2 The MyISAM Storage Engine

MyISAM 基于较早的(现已不可用的)ISAM 存储引擎,但具有许多有用的扩展功能。MyISAM is based on the older (and no longer available) ISAM storage engine but has many useful extensions.

表 18.2 MyISAM 存储引擎特性Table 18.2 MyISAM Storage Engine Features

功能Feature 支持情况Support
B 树索引B-tree indexes 是Yes
备份/时间点恢复(在服务器中实现,而非在存储引擎中实现。)Backup/point-in-time recovery (Implemented in the server, rather than in the storage engine.) 是Yes
集群数据库支持Cluster database support 否No
聚簇索引Clustered indexes 否No
压缩数据Compressed data 是的(压缩的 MyISAM 表仅在使用压缩行格式时受支持。使用 MyISAM 的压缩行格式的表为只读。)Yes (Compressed MyISAM tables are supported only when using the compressed row format. Tables using the compressed row format with MyISAM are read only.)
数据缓存Data caches 否No
加密数据Encrypted data 是的(通过服务器的加密函数实现。)Yes (Implemented in the server via encryption functions.)
外键支持Foreign key support 否No
全文搜索索引Full-text search indexes 是Yes
地理空间数据类型支持Geospatial data type support 是Yes
地理空间索引支持Geospatial indexing support 是Yes
哈希索引Hash indexes 否No
索引缓存Index caches 是Yes
锁粒度Locking granularity 表Table
多版本并发控制 (MVCC)MVCC 否No
复制支持(在服务器中实现,而不是在存储引擎中。)Replication support (Implemented in the server, rather than in the storage engine.) 是Yes
存储限制Storage limits 256TB
T 树索引T-tree indexes 否No
事务Transactions 否No
更新数据字典统计信息Update statistics for data dictionary 是Yes

每个 MyISAM 表在磁盘上存储为两个文件。文件名以表名开头,并有一个扩展名来指示文件类型。数据文件的扩展名为 .MYD(MYData)。索引文件的扩展名为 .MYI(MYIndex)。表定义存储在 MySQL 数据字典中。Each MyISAM table is stored on disk in two files. The files have names that begin with the table name and have an extension to indicate the file type. The data file has an .MYD (MYData) extension. The index file has an .MYI (MYIndex) extension. The table definition is stored in the MySQL data dictionary.

要明确指定您想要一个 MyISAM 表,请使用 ENGINE 表选项指明:To specify explicitly that you want a MyISAM table, indicate that with an ENGINE table option:

CREATE TABLE t (i INT) ENGINE = MYISAM;

在 MySQL 8.4 中,通常需要使用 ENGINE 来指定 MyISAM 存储引擎,因为 InnoDB 是默认引擎。In MySQL 8.4, it is normally necessary to use ENGINE to specify the MyISAM storage engine because InnoDB is the default engine.

您可以使用 mysqlcheck 客户端或 myisamchk 工具检查或修复 MyISAM 表。您还可以使用 myisampack 压缩 MyISAM 表,以占用更少的空间。请参阅 第 6.5.3 节,“mysqlcheck — 表维护程序”、第 6.6.4 节,“myisamchk — MyISAM 表维护工具” 和 第 6.6.6 节,“myisampack — 生成压缩的只读 MyISAM 表”。You can check or repair MyISAM tables with the mysqlcheck client or myisamchk utility. You can also compress MyISAM tables with myisampack to take up much less space. See Section 6.5.3, “mysqlcheck — A Table Maintenance Program”, Section 6.6.4, “myisamchk — MyISAM Table-Maintenance Utility”, and Section 6.6.6, “myisampack — Generate Compressed, Read-Only MyISAM Tables”.

在 MySQL 8.4 中,MyISAM 存储引擎不支持分区。在以前版本的 MySQL 中创建的分区 MyISAM 表不能在 MySQL 8.4 中使用。有关更多信息,请参见 第 26.6.2 节,“分区与存储引擎相关的限制”。有关升级此类表以便在 MySQL 8.4 中使用的帮助,请参见 第 3.5 节,“MySQL 8.4 中的更改”。In MySQL 8.4, the MyISAM storage engine provides no partitioning support. Partitioned MyISAM tables created in previous versions of MySQL cannot be used in MySQL 8.4. For more information, see Section 26.6.2, “Partitioning Limitations Relating to Storage Engines”. For help with upgrading such tables so that they can be used in MySQL 8.4, see Section 3.5, “Changes in MySQL 8.4”.

MyISAM 表具有以下特性:MyISAM tables have the following characteristics:

  • 所有数据值都以低字节优先的方式存储。这使得数据与机器和操作系统无关。二进制可移植性的唯一要求是机器使用二进制补码有符号整数和 IEEE 浮点格式。这些要求在主流机器中被广泛使用。二进制兼容性可能不适用于嵌入式系统,因为这些系统有时采用特殊处理器。All data values are stored with the low byte first. This makes the data machine and operating system independent. The only requirements for binary portability are that the machine uses two's-complement signed integers and IEEE floating-point format. These requirements are widely used among mainstream machines. Binary compatibility might not be applicable to embedded systems, which sometimes have peculiar processors.

    以低字节优先存储数据不会产生明显的速度损失;表行中的字节通常是未对齐的,按顺序读取未对齐字节所需的处理时间并不比反向读取多。此外,与其他代码相比,服务器中获取列值的代码并不是时间关键型的。There is no significant speed penalty for storing data low byte first; the bytes in a table row normally are unaligned and it takes little more processing to read an unaligned byte in order than in reverse order. Also, the code in the server that fetches column values is not time critical compared to other code.

  • 所有数值键值都以高字节优先存储,以便实现更好的索引压缩。All numeric key values are stored with the high byte first to permit better index compression.

  • 在支持大文件的文件系统和操作系统上,支持大文件(最大可达 63 位文件长度)。Large files (up to 63-bit file length) are supported on file systems and operating systems that support large files.

  • MyISAM 表的行数限制为 (232)2(1.844E 19)。There is a limit of (232)2 (1.844E+19) rows in a MyISAM table.

  • MyISAM 表的最大索引数量为 64。The maximum number of indexes per MyISAM table is 64.

    每个索引的最大列数为 16。The maximum number of columns per index is 16.

  • 最大键长度为 1000 字节。也可以通过修改源代码并重新编译来更改。对于长度超过 250 字节的键,会使用比默认 1024 字节更大的键块大小。The maximum key length is 1000 bytes. This can also be changed by changing the source and recompiling. For the case of a key longer than 250 bytes, a larger key block size than the default of 1024 bytes is used.

  • 当按排序顺序插入行(例如使用 AUTO_INCREMENT 列时),索引树会被分裂,使高层节点只包含一个键。这可以提高索引树的空间利用率。When rows are inserted in sorted order (as when you are using an AUTO_INCREMENT column), the index tree is split so that the high node only contains one key. This improves space utilization in the index tree.

  • 每张表支持对一列 AUTO_INCREMENT 的内部处理。MyISAM 会自动为 INSERT 和 UPDATE 操作更新该列。这使得 AUTO_INCREMENT 列更快(至少快 10%)。序列顶端的值在被删除后不会被重用。(当 AUTO_INCREMENT 列被定义为多列索引的最后一列时,被删除的序列顶端的值会被重用。)AUTO_INCREMENT 值可以通过 ALTER TABLE 或 myisamchk 来重置。Internal handling of one AUTO_INCREMENT column per table is supported. MyISAM automatically updates this column for INSERT and UPDATE operations. This makes AUTO_INCREMENT columns faster (at least 10%). Values at the top of the sequence are not reused after being deleted. (When an AUTO_INCREMENT column is defined as the last column of a multiple-column index, reuse of values deleted from the top of a sequence does occur.) The AUTO_INCREMENT value can be reset with ALTER TABLE or myisamchk.

  • 在混合删除、更新和插入操作时,动态大小的行的碎片化要少得多。这是通过自动合并相邻的已删除块以及在下一个块被删除时扩展块来实现的。Dynamic-sized rows are much less fragmented when mixing deletes with updates and inserts. This is done by automatically combining adjacent deleted blocks and by extending blocks if the next block is deleted.

  • MyISAM 支持并发插入:如果表在数据文件中间没有空闲块,你可以在其他线程从表中读取的同时INSERT 新行。空闲块可能由于删除行或动态长度行更新导致新数据比现有内容更多而产生。当所有空闲块用完(填满)时,后续插入操作又可以并发执行。请参阅 第 10.11.3 节,“并发插入”。MyISAM supports concurrent inserts: If a table has no free blocks in the middle of the data file, you can INSERT new rows into it at the same time that other threads are reading from the table. A free block can occur as a result of deleting rows or an update of a dynamic length row with more data than its current contents. When all free blocks are used up (filled in), future inserts become concurrent again. See Section 10.11.3, “Concurrent Inserts”.

  • 您可以将数据文件和索引文件放在不同的目录和不同的物理设备上,以利用 DATA DIRECTORY 和 INDEX DIRECTORY 表选项在 CREATE TABLE 中获得更高的速度。参见 第 15.1.20 节,“CREATE TABLE 语句”。You can put the data file and index file in different directories on different physical devices to get more speed with the DATA DIRECTORY and INDEX DIRECTORY table options to CREATE TABLE. See Section 15.1.20, “CREATE TABLE Statement”.

  • BLOB 和 TEXT 列可以建立索引。BLOB and TEXT columns can be indexed.

  • 索引列允许 NULL 值。每个键占用 0 到 1 字节。NULL values are permitted in indexed columns. This takes 0 to 1 bytes per key.

  • 每个字符列可以有不同的字符集。参见第 12 章,字符集、校对规则、Unicode。Each character column can have a different character set. See Chapter 12, Character Sets, Collations, Unicode.

  • MyISAM索引文件中有一个标志,指示表是否正确关闭。如果mysqld是以设置了myisam_recover_options系统变量的方式启动的,当打开MyISAM表时,会自动检查表,并在表未正确关闭的情况下进行修复。There is a flag in the MyISAM index file that indicates whether the table was closed correctly. If mysqld is started with the myisam_recover_options system variable set, MyISAM tables are automatically checked when opened, and are repaired if the table wasn't closed properly.

  • myisamchk 如果使用 --update-state 选项运行,它会将表标记为已检查。myisamchk --fast 只检查没有此标记的表。myisamchk marks tables as checked if you run it with the --update-state option. myisamchk --fast checks only those tables that don't have this mark.

  • myisamchk --analyze 存储键部分以及整个键的统计信息。myisamchk --analyze stores statistics for portions of keys, as well as for entire keys.

  • myisampack 可以打包 BLOB 和 VARCHAR 列。myisampack can pack BLOB and VARCHAR columns.

MyISAM 还支持以下功能:MyISAM also supports the following features:

  • 支持真正的 VARCHAR 类型;VARCHAR 列以存储在一或两字节中的长度开始。Support for a true VARCHAR type; a VARCHAR column starts with a length stored in one or two bytes.

  • 包含 VARCHAR 列的表可以具有固定或动态行长度。Tables with VARCHAR columns may have fixed or dynamic row length.

  • 表中 VARCHAR 和 CHAR 列的长度总和可以达到 64KB。The sum of the lengths of the VARCHAR and CHAR columns in a table may be up to 64KB.

  • 任意长度的 UNIQUE 约束。Arbitrary length UNIQUE constraints.

额外资源Additional Resources