myisampack 工具用于压缩 MyISAM 表。myisampack 通过分别压缩表中的每一列来工作。通常,myisampack 可以将数据文件压缩 40% 到 70%。The myisampack utility compresses
MyISAM tables. myisampack
works by compressing each column in the table separately.
Usually, myisampack packs the data file 40%
to 70%.
当表格在稍后使用时,服务器会将解压列所需的信息读取到内存中。这在访问单独行时会带来更好的性能,因为你只需要解压一行。When the table is used later, the server reads into memory the information needed to decompress columns. This results in much better performance when accessing individual rows, because you only have to uncompress exactly one row.
MySQL 在可能的情况下使用 mmap() 对压缩表执行内存映射。如果 mmap() 无法工作,MySQL 会回退到普通的读/写文件操作。MySQL uses mmap() when possible to perform
memory mapping on compressed tables. If
mmap() does not work, MySQL falls back to
normal read/write file operations.
请注意以下事项:Please note the following:
如果mysqld 服务器是在禁用外部锁定的情况下启动的,那么在表可能在打包过程中被服务器更新的情况下调用 myisampack 并不是一个好主意。最安全的方法是在服务器停止时压缩表。If the mysqld server was invoked with external locking disabled, it is not a good idea to invoke myisampack if the table might be updated by the server during the packing process. It is safest to compress tables with the server stopped.
打包表格后,它将变为只读。这通常是有意为之(例如在访问光盘上的打包表格时)。After packing a table, it becomes read only. This is generally intended (such as when accessing packed tables on a CD).
myisampack 不支持分区表。myisampack does not support partitioned tables.
像这样调用 myisampack:Invoke myisampack like this:
myisampack [options]file_name...
每个文件名参数应该是一个索引文件(.MYI)的名称。如果您不在数据库目录中,应指定文件的路径名。可以省略 .MYI 扩展名。Each file name argument should be the name of an index
(.MYI) file. If you are not in the database
directory, you should specify the path name to the file. It is
permissible to omit the .MYI extension.
在使用 myisampack 压缩表之后,使用 myisamchk -rq 重建其索引。第 6.6.4 节,“myisamchk — MyISAM 表维护工具”。After you compress a table with myisampack, use myisamchk -rq to rebuild its indexes. Section 6.6.4, “myisamchk — MyISAM Table-Maintenance Utility”.
myisampack 支持以下选项。它还能读取选项文件,并支持在 第 6.2.2.3 节,“影响选项文件处理的命令行选项” 中描述的处理选项。myisampack supports the following options. It also reads option files and supports the options for processing them described at Section 6.2.2.3, “Command-Line Options that Affect Option-File Handling”.
--help,-?命令行格式Command-Line Format --help--help显示帮助信息并退出。Display a help message and exit.
--backup,-b命令行格式Command-Line Format --backup使用名称
备份每个表的数据文件。Make a backup of each table's data file using the nametbl_name.OLD.tbl_name.OLD--character-sets-dir=dir_name--character-sets-dir=dir_name命令行格式Command-Line Format --character-sets-dir=dir_name--character-sets-dir=dir_name类型Type 目录名称Directory name 安装字符集的目录。请参见第 12.15 节,“字符集配置”。The directory where character sets are installed. See Section 12.15, “Character Set Configuration”.
--debug[=debug_options],-# [debug_options]--debug[=,debug_options]-# [debug_options]命令行格式Command-Line Format --debug[=debug_options]--debug[=debug_options]类型Type 字符串String 默认值Default Value d:t:o写入调试日志。典型的
debug_options字符串是d:t:o,。默认值是file_named:t:o。Write a debugging log. A typicaldebug_optionsstring isd:t:o,. The default isfile_named:t:o.此选项仅在 MySQL 使用
WITH_DEBUG构建时可用。Oracle 提供的 MySQL 发行版二进制文件 未 使用此选项构建。This option is available only if MySQL was built usingWITH_DEBUG. MySQL release binaries provided by Oracle are not built using this option.--force,-f命令行格式Command-Line Format --force即使生成的表比原表大,或者之前调用中间文件已存在,也要生成压缩表。myisampack exists. (myisampack在压缩表的同时,会在数据库目录中创建一个名为
的中间文件。如果你终止myisampack,这个tbl_name.TMD.TMD文件可能不会被删除。)通常情况下,myisampack如果发现存在,会以错误退出。使用tbl_name.TMD--force, myisampack仍然会压缩表。Produce a packed table even if it becomes larger than the original or if the intermediate file from an earlier invocation of myisampack exists. (myisampack creates an intermediate file namedin the database directory while it compresses the table. If you kill myisampack, thetbl_name.TMD.TMDfile might not be deleted.) Normally, myisampack exits with an error if it finds thatexists. Withtbl_name.TMD--force, myisampack packs the table anyway.--join=,big_tbl_name-jbig_tbl_name命令行格式Command-Line Format --join=big_tbl_name类型Type 字符串String 将命令行中指定的所有表合并为一个单一的打包表
big_tbl_name。所有要合并的表 必须 具有相同的结构(相同的列名和类型,相同的索引,等等)。Join all tables named on the command line into a single packed tablebig_tbl_name. All tables that are to be combined must have identical structure (same column names and types, same indexes, and so forth).big_tbl_name在合并操作之前必须不存在。命令行中要合并到big_tbl_name的所有源表必须存在。源表在合并操作中会被读取,但不会被修改。big_tbl_namemust not exist prior to the join operation. All source tables named on the command line to be merged intobig_tbl_namemust exist. The source tables are read for the join operation but not modified.--silent,-s命令行格式Command-Line Format --silent静音模式。仅在发生错误时输出。Silent mode. Write output only when errors occur.
--test,-t命令行格式Command-Line Format --test不要真正打包桌子,只是测试打包它。Do not actually pack the table, just test packing it.
--tmpdir=dir_name,-T dir_name--tmpdir=,dir_name-Tdir_name命令行格式Command-Line Format --tmpdir=dir_name--tmpdir=dir_name类型Type 目录名称Directory name 使用指定的目录作为 myisampack 创建临时文件的位置。Use the named directory as the location where myisampack creates temporary files.
--verbose,-v命令行格式Command-Line Format --verbose--verbose详细模式。写出关于打包操作进度及其结果的信息。Verbose mode. Write information about the progress of the packing operation and its result.
--version,-V命令行格式Command-Line Format --version显示版本信息并退出。Display version information and exit.
--wait,-w命令行格式Command-Line Format --wait如果表正在使用中,则等待并重试。如果mysqld服务器在调用时禁用了外部锁定,那么在表可能在压缩过程中被服务器更新的情况下调用myisampack不是一个好主意。Wait and retry if the table is in use. If the mysqld server was invoked with external locking disabled, it is not a good idea to invoke myisampack if the table might be updated by the server during the packing process.
以下命令序列演示了一个典型的表压缩会话:The following sequence of commands illustrates a typical table compression session:
$>ls -l station.*-rw-rw-r-- 1 jones my 994128 Apr 17 19:00 station.MYD -rw-rw-r-- 1 jones my 53248 Apr 17 19:00 station.MYI $>myisamchk -dvv stationMyISAM file: station Isam-version: 2 Creation time: 1996-03-13 10:08:58 Recover time: 1997-02-02 3:06:43 Data records: 1192 Deleted blocks: 0 Datafile parts: 1192 Deleted data: 0 Datafile pointer (bytes): 2 Keyfile pointer (bytes): 2 Max datafile length: 54657023 Max keyfile length: 33554431 Recordlength: 834 Record format: Fixed length table description: Key Start Len Index Type Root Blocksize Rec/key 1 2 4 unique unsigned long 1024 1024 1 2 32 30 multip. text 10240 1024 1 Field Start Length Type 1 1 1 2 2 4 3 6 4 4 10 1 5 11 20 6 31 1 7 32 30 8 62 35 9 97 35 10 132 35 11 167 4 12 171 16 13 187 35 14 222 4 15 226 16 16 242 20 17 262 20 18 282 20 19 302 30 20 332 4 21 336 4 22 340 1 23 341 8 24 349 8 25 357 8 26 365 2 27 367 2 28 369 4 29 373 4 30 377 1 31 378 2 32 380 8 33 388 4 34 392 4 35 396 4 36 400 4 37 404 1 38 405 4 39 409 4 40 413 4 41 417 4 42 421 4 43 425 4 44 429 20 45 449 30 46 479 1 47 480 1 48 481 79 49 560 79 50 639 79 51 718 79 52 797 8 53 805 1 54 806 1 55 807 20 56 827 4 57 831 4 $>myisampack station.MYICompressing station.MYI: (1192 records) - Calculating statistics normal: 20 empty-space: 16 empty-zero: 12 empty-fill: 11 pre-space: 0 end-space: 12 table-lookups: 5 zero: 7 Original trees: 57 After join: 17 - Compressing file 87.14% Remember to run myisamchk -rq on compressed tables $>myisamchk -rq station- check record delete-chain - recovering (with sort) MyISAM-table 'station' Data records: 1192 - Fixing index 1 - Fixing index 2 $>mysqladmin -uroot flush-tables$>ls -l station.*-rw-rw-r-- 1 jones my 127874 Apr 17 19:00 station.MYD -rw-rw-r-- 1 jones my 55296 Apr 17 19:04 station.MYI $>myisamchk -dvv stationMyISAM file: station Isam-version: 2 Creation time: 1996-03-13 10:08:58 Recover time: 1997-04-17 19:04:26 Data records: 1192 Deleted blocks: 0 Datafile parts: 1192 Deleted data: 0 Datafile pointer (bytes): 3 Keyfile pointer (bytes): 1 Max datafile length: 16777215 Max keyfile length: 131071 Recordlength: 834 Record format: Compressed table description: Key Start Len Index Type Root Blocksize Rec/key 1 2 4 unique unsigned long 10240 1024 1 2 32 30 multip. text 54272 1024 1 Field Start Length Type Huff tree Bits 1 1 1 constant 1 0 2 2 4 zerofill(1) 2 9 3 6 4 no zeros, zerofill(1) 2 9 4 10 1 3 9 5 11 20 table-lookup 4 0 6 31 1 3 9 7 32 30 no endspace, not_always 5 9 8 62 35 no endspace, not_always, no empty 6 9 9 97 35 no empty 7 9 10 132 35 no endspace, not_always, no empty 6 9 11 167 4 zerofill(1) 2 9 12 171 16 no endspace, not_always, no empty 5 9 13 187 35 no endspace, not_always, no empty 6 9 14 222 4 zerofill(1) 2 9 15 226 16 no endspace, not_always, no empty 5 9 16 242 20 no endspace, not_always 8 9 17 262 20 no endspace, no empty 8 9 18 282 20 no endspace, no empty 5 9 19 302 30 no endspace, no empty 6 9 20 332 4 always zero 2 9 21 336 4 always zero 2 9 22 340 1 3 9 23 341 8 table-lookup 9 0 24 349 8 table-lookup 10 0 25 357 8 always zero 2 9 26 365 2 2 9 27 367 2 no zeros, zerofill(1) 2 9 28 369 4 no zeros, zerofill(1) 2 9 29 373 4 table-lookup 11 0 30 377 1 3 9 31 378 2 no zeros, zerofill(1) 2 9 32 380 8 no zeros 2 9 33 388 4 always zero 2 9 34 392 4 table-lookup 12 0 35 396 4 no zeros, zerofill(1) 13 9 36 400 4 no zeros, zerofill(1) 2 9 37 404 1 2 9 38 405 4 no zeros 2 9 39 409 4 always zero 2 9 40 413 4 no zeros 2 9 41 417 4 always zero 2 9 42 421 4 no zeros 2 9 43 425 4 always zero 2 9 44 429 20 no empty 3 9 45 449 30 no empty 3 9 46 479 1 14 4 47 480 1 14 4 48 481 79 no endspace, no empty 15 9 49 560 79 no empty 2 9 50 639 79 no empty 2 9 51 718 79 no endspace 16 9 52 797 8 no empty 2 9 53 805 1 17 1 54 806 1 3 9 55 807 20 no empty 3 9 56 827 4 no zeros, zerofill(2) 2 9 57 831 4 no zeros, zerofill(1) 2 9
myisampack 显示以下类型的信息:myisampack displays the following kinds of information:
normalnormal未使用额外打包的列数。The number of columns for which no extra packing is used.
empty-spaceempty-space仅包含空格值的列数。这些占用一位。The number of columns containing values that are only spaces. These occupy one bit.
empty-zeroempty-zero仅包含二进制零值的列数。这些占用一位。The number of columns containing values that are only binary zeros. These occupy one bit.
empty-fillempty-fill整数列的数量未占用其类型的完整字节范围。这些列会被更改为较小的类型。例如,如果一个
BIGINT列(8 个字节)中的所有值都在-128到127的范围内,则可以存储为TINYINT列(1 个字节)。The number of integer columns that do not occupy the full byte range of their type. These are changed to a smaller type. For example, aBIGINTcolumn (eight bytes) can be stored as aTINYINTcolumn (one byte) if all its values are in the range from-128to127.pre-spacepre-space带前导空格存储的小数列数。在这种情况下,每个值包含前导空格的数量。The number of decimal columns that are stored with leading spaces. In this case, each value contains a count for the number of leading spaces.
end-spaceend-space具有大量尾随空格的列数。在这种情况下,每个值都包含尾随空格的数量。The number of columns that have a lot of trailing spaces. In this case, each value contains a count for the number of trailing spaces.
table-lookuptable-lookup该列只有少量不同的值,这些值在霍夫曼压缩之前被转换为
ENUM。The column had only a small number of different values, which were converted to anENUMbefore Huffman compression.zerozero所有值都为零的列数。The number of columns for which all values are zero.
Original treesOriginal trees初始的霍夫曼树数量。The initial number of Huffman trees.
After joinAfter join在合并树以节省一些头部空间后剩下的不同哈夫曼树的数量。The number of distinct Huffman trees left after joining trees to save some header space.
在表被压缩之后,由 myisamchk -dvv 显示的 Field 行包括关于每一列的附加信息:After a table has been compressed, the Field
lines displayed by myisamchk -dvv include
additional information about each column:
TypeType数据类型。该值可能包含以下任意描述符:The data type. The value may contain any of the following descriptors:
constantconstant所有行的值都相同。All rows have the same value.
no endspaceno endspace不要存储尾部空格。Do not store endspace.
no endspace, not_alwaysno endspace, not_always不要存储结尾空格,并且不要对所有值进行结尾空格压缩。Do not store endspace and do not do endspace compression for all values.
no endspace, no emptyno endspace, no empty不要存储末尾空格。不要存储空值。Do not store endspace. Do not store empty values.
table-lookuptable-lookupzerofill(N)zerofill(N)值中最重要的
N个字节始终为 0,并且不会被存储。The most significantNbytes in the value are always 0 and are not stored.no zerosno zeros不要存储零。Do not store zeros.
always zeroalways zero零值使用一位存储。Zero values are stored using one bit.
Huff treeHuff tree与该列相关的霍夫曼树的编号。The number of the Huffman tree associated with the column.
BitsBits霍夫曼树中使用的位数。The number of bits used in the Huffman tree.
在运行 myisampack 后,使用 myisamchk 重新创建任何索引。此时,您也可以对索引块进行排序,并创建 MySQL 优化器高效运行所需的统计信息:After you run myisampack, use myisamchk to re-create any indexes. At this time, you can also sort the index blocks and create statistics needed for the MySQL optimizer to work more efficiently:
myisamchk -rq --sort-index --analyze tbl_name.MYI
在将压缩表安装到 MySQL 数据库目录后,您应执行 mysqladmin flush-tables 来强制 mysqld 开始使用新表。After you have installed the packed table into the MySQL database directory, you should execute mysqladmin flush-tables to force mysqld to start using the new table.
要解包已打包的表,请使用 --unpack 选项执行 myisamchk。To unpack a packed table, use the
--unpack option to
myisamchk.