MYISAMCHK(1)
๐ MYISAMCHK ๐
okay bestie, buckle UP, because we're talking about myisamchk, the MyISAM table-maintenance utility from the MariaDB Database System manual. yes, that manual. the one with the all-caps title. we're making it cute now. ๐
โจ NAME โจ
myisamchk โ the MyISAM table-maintenance utility ๐ ๏ธ๐
๐ธ SYNOPSIS ๐ธ
myisamchk [options] tbl_name ...
๐ฆ DESCRIPTION ๐ฆ
so like, the tea is this: the myisamchk utility gets information about your database tables, or checks them, repairs them, or optimizes them. it's giving table glow-up. โจ myisamchk works with MyISAM tables, aka tables that have .MYD and .MYI files for storing data and indexes. those two files? iconic duo. main character energy fr.
heads up though: using myisamchk with partitioned tables is not supported. nope. not happening. don't try it. ๐
โ๏ธ
Caution bestie please, it is best to make a backup of a table before performing a table repair operation, because under some circumstances the operation might cause data loss. ๐ญ possible causes include but are not limited to file system errors. so like. back it up. i'm literally begging.
invoke myisamchk like this:
shell> myisamchk [options] tbl_name ...
the options specify what you want myisamchk to do, and they're described in the following sections. you can also get a list of options by invoking myisamchk --help. handy!! ๐ซถ
with no options, myisamchk simply checks your table as the default operation. that's the default vibe. to get more information, or to tell myisamchk to take corrective action, you specify options as described in the following discussion. okay so let's talk about the arguments:
tbl_name is the database table you want to check or repair. now here's the thing โ if you run myisamchk somewhere other than in the database directory, you must specify the path to the database directory, because myisamchk has no idea where the database is located. it's not psychic, it's just a utility. ๐
in fact โ and this is lowkey iconic โ myisamchk does not actually care whether the files you are working on are located in a database directory. you can copy the files that correspond to a database table into some other location and perform recovery operations on them there. wherever. it doesn't care. it's chill like that. ๐
you can name several tables on the myisamchk command line if you wish. you can also specify a table by naming its index file (the file with the .MYI suffix). this allows you to specify all tables in a directory by using the pattern *.MYI. for example, if you are in a database directory, you can check all the MyISAM tables in that directory like this:
shell> myisamchk *.MYI
if you are not in the database directory, you can check all the tables there by specifying the path to the directory:
shell> myisamchk /path/to/database_dir/*.MYI
and you can even check all tables in all databases by specifying a wildcard with the path to the MariaDB data directory:
shell> myisamchk /path/to/datadir/*/*.MYI
โญ the recommended quick check โญ
the recommended way to quickly check all MyISAM tables is:
shell> myisamchk --silent --fast /path/to/datadir/*/*.MYI
short. sweet. slay. ๐
if you want to check all MyISAM tables and repair any that are corrupted, you can use the following command:
shell> myisamchk --silent --force --fast --update-state \
--key_buffer_size=64M --sort_buffer_size=64M \
--read_buffer_size=1M --write_buffer_size=1M \
/path/to/datadir/*/*.MYI
this command assumes that you have more than 64MB free. ๐พ for more information about memory allocation with myisamchk, see the section called "MYISAMCHK MEMORY USAGE". (we'll get there, don't worry ๐ง)
๐ฅ important (read this one fr fr) ๐ฅ
Important you must ensure that no other program is using the tables while you are runningmyisamchk. the most effective means of doing so is to shut down the MariaDB server while runningmyisamchk, or to lock all tables thatmyisamchkis being used on. no sharing. this is a solo activity. ๐
otherwise, when you run myisamchk, it may display the following error message:
warning: clients are using or haven't closed the table properly
this means that you are trying to check a table that has been updated by another program (such as the mariadbd server) that hasn't yet closed the file, or that has died without closing the file properly, which can sometimes lead to the corruption of one or more MyISAM tables. ๐ not the corruption. we do not want that.
if mariadbd is running, you must force it to flush any table modifications that are still buffered in memory by using FLUSH TABLES. you should then ensure that no one is using the tables while you are running myisamchk.
however โ and this is the cheat code โ the easiest way to avoid this problem is to use CHECK TABLE instead of myisamchk to check tables. ๐
myisamchk supports the following options, which can be specified on the command line or in the [myisamchk] option file group. ๐
okay but wait, there's more โ the options list is coming up next and bestie, it is LONG. stay with me. ๐ซถ
โจ MYISAMCHK GENERAL OPTIONS โจ
okay so bestie, these options? they're the universal ones ๐ you can use them with literally any kind of table maintenance myisamchk does. The sections after this one are the picky ones โ they only show up for specific operations like checking or repairing. This section? It's for everyone. ๐ซถ
--help,-?โ Shows you a help message and dips. The options are grouped by what kind of operation they do. ๐--HELP,-Hโ Also shows a help message and dips, but this time everything's in one big single list. no grouping, just vibes. โจ--debug=debug_options,-# debug_optionsโ Writes a debugging log. A typicaldebug_optionsstring is'd:t:o,file_name'. The default is'd:t:o,/tmp/myisamchk.trace'. ๐ฆ--silent,-sโ Silent mode, literally. Output only happens when errors occur. And you can stack it โ use-stwice (-ss) to make myisamchk very silent. ๐คซ--verbose,-vโ Verbose mode. Prints more info about what the program is doing. Works with-dand-e. Stack it up (-vv,-vvv) for even MORE output. ๐--version,-Vโ Shows version info and exits. ๐ธ--wait,-wโ Instead of throwing an error when the table is locked, it just... waits. until the table is unlocked, then keeps going. Heads up tho: if you're runningmariadbdwith external locking disabled, the table can only be locked by anothermyisamchkcommand. ๐--print-defaultsโ Prints the program argument list and exits. ๐--no-defaultsโ Don't read default options from any option file. ๐--defaults-file=#โ Only read default options from the given file. ๐--defaults-extra-file=#โ Read this file after the global files are read. โญ
You can also set these variables using the --var_name=value syntax. Here's the whole squad and their default values:
decode_bitsโ9ft_max_word_lenโ version-dependentft_min_word_lenโ4ft_stopword_fileโ built-in listkey_buffer_sizeโ523264key_cache_block_sizeโ1024myisam_block_sizeโ1024read_buffer_sizeโ262136sort_buffer_sizeโ2097144sort_key_blocksโ16stats_methodโnulls_unequalwrite_buffer_sizeโ262136
The possible myisamchk variables and their default values can be examined with myisamchk --help:
sort_buffer_size gets used when the keys are repaired by sorting keys โ which is the normal case when you use --recover. ๐ฅ
key_buffer_size gets used when you're checking the table with --extend-check, or when the keys are repaired by inserting keys row by row into the table (like when doing normal inserts). Repairing through the key buffer is used in these cases:
- You use
--safe-recover. - The temporary files needed to sort the keys would be more than twice as big as when creating the key file directly. This is often the case when you have large key values for
CHAR,VARCHAR, orTEXTcolumns, because the sort operation needs to store the complete key values as it proceeds. If you have lots of temporary space and you can force myisamchk to repair by sorting, you can use the--sort-recoveroption.
Repairing through the key buffer takes much less disk space than using sorting, but it's also much slower. ๐ญ
If you want a faster repair, set the key_buffer_size and sort_buffer_size variables to about 25% of your available memory. You can set both variables to large values, because only one of them is used at a time. ๐ง
myisam_block_size is the size used for index blocks.
stats_method influences how NULL values are treated for index statistics collection when the --analyze option is given. It acts like the myisam_stats_method system variable. For more information, see the description of myisam_stats_method in Section 5.1.4, "Server System Variables", and Section 7.4.7, "MyISAM Index Statistics Collection".
ft_min_word_len and ft_max_word_len indicate the minimum and maximum word length for FULLTEXT indexes. ft_stopword_file names the stopword file. These need to be set under the following circumstances. ๐
If you use myisamchk to perform an operation that modifies table indexes (such as repair or analyze), the FULLTEXT indexes are rebuilt using the default full-text parameter values for minimum and maximum word length and the stopword file โ unless you specify otherwise. This can result in queries failing. ๐
The problem occurs because these parameters are known only by the server. They are not stored in MyISAM index files. To avoid the problem if you have modified the minimum or maximum word length or the stopword file in the server, specify the same ft_min_word_len, ft_max_word_len, and ft_stopword_file values to myisamchk that you use for mariadbd. For example, if you have set the minimum word length to 3, you can repair a table with myisamchk like this:
shell> myisamchk --recover --ft_min_word_len=3 tbl_name.MYI
To ensure that myisamchk and the server use the same values for full-text parameters, you can place each one in both the [mariadbd] and [myisamchk] sections of an option file:
[mariadbd]
ft_min_word_len=3
[myisamchk]
ft_min_word_len=3
An alternative to using myisamchk is to use the REPAIR TABLE, ANALYZE TABLE, OPTIMIZE TABLE, or ALTER TABLE. These statements are performed by the server, which knows the proper full-text parameter values to use. ๐
๐ MYISAMCHK CHECK OPTIONS ๐
myisamchk supports these options for table checking operations, bestie. go off:
--check,-cโ Checks the table for errors. This is the default operation if you specify no option that selects an operation type explicitly. it's the main character of defaults ๐--check-only-changed,-Cโ Only checks tables that have changed since the last check. โจ--extend-check,-eโ Checks the table very thoroughly. This is quite slow if the table has many indexes. This option should only be used in extreme cases. Normally,myisamchkormyisamchk --medium-checkshould be able to determine whether there are any errors in the table.
If you're using --extend-check and have plenty of memory, setting the key_buffer_size variable to a large value helps the repair operation run faster.
For a description of the output format, see the section called "MYISAMCHK TABLE INFORMATION".
--fast,-Fโ Only checks tables that haven't been closed properly. ๐ซถ--force,-fโ Does a repair operation automatically if myisamchk finds any errors in the table. The repair type is the same as that specified with the--recoveror-roption. States will be updated as with--update-state. ๐ฅ--information,-iโ Prints informational statistics about the table that is checked. ๐--medium-check,-mโ Does a check that is faster than an--extend-checkoperation. This finds only 99.99% of all errors, which should be good enough in most cases. ๐ธ--read-only,-Tโ Do not mark the table as checked. This is useful if you use myisamchk to check a table that is in use by some other application that does not use locking, such asmariadbdwhen run with external locking disabled. ๐--update-state,-Uโ Stores information in the.MYIfile to indicate when the table was checked and whether the table crashed. This should be used to get full benefit of the--check-only-changedoption, but you shouldn't use this option if themariadbdserver is using the table and you are running it with external locking disabled. โ ๏ธ
ngl that last one is a real "don't do it bestie" moment โ if the server's using the table and external locking is off, just leave -U alone, fr fr. ๐ญ
๐ง MYISAMCHK REPAIR OPTIONS ๐ง
okay bestie, these are the glow-up options ๐
โ the ones that actually kick in when you hand myisamchk a repair job (aka when you pass something like --recover or --safe-recover). buckle up.
--backup,-Bโ makes a backup of the.MYDfile, saved asfile_name-time.BAK๐ซถ--character-sets-dir=pathโ the directory where your character sets live, i.e. where they're installed.--correct-checksumโ fixes up the checksum info for the table. slay.--create-missing-keysโ creates keys that are missing. this one assumes the data file is correct and that the number of rows stored in the index file is correct. it also turns on--quickfor you, no cap.--data-file-length=len,-D lenโ the max length the data file is allowed to be (used when re-creating the data file because it's "full").--extend-check,-eโ a repair that tries so hard to recover every possible row from the data file. problem is, normally it also finds a whole bunch of garbage rows ๐๏ธ. do not use this unless you are genuinely desperate.
for a description of the output format, go look at the section called "MYISAMCHK TABLE INFORMATION".
--force,-fโ overwrites old intermediate files (the ones with names liketbl_name.TMD) instead of just aborting. and if you add another--forceon top, you dodge'myisam_sort_buffer_size is too small'errors. in that case it'll try the repair with whatevermyisam_sort_buffer_sizeyou gave it and dynamically allocate as many management buffers as it needs. iconic.--keys-used=val,-k valโ formyisamchk, this value is a bit-value that says which indexes to update. each binary bit maps to a table index, and the first index is bit 0. a value of0disables updates to all indexes, which you can use to get faster inserts. and deactivated indexes? you can bring them back withmyisamchk -r. ๐ซ--max-record-length=lenโ skips rows bigger than the length you give, for whenmyisamchkcan't allocate the memory to hold them.--parallel-recover,-pโ uses the same technique as-rand-n, but creates all the keys in parallel, using different threads. heads up bestie: this is beta-quality code. use at your own risk! ๐
seriously, beta. your risk. i said what i said.
--quick,-qโ a faster repair, achieved by modifying only the index file and not the data file. you can pass this option twice to forcemyisamchkto modify the original data file in case of duplicate keys. NOTE: tables where the data file is corrupted can't be fixed with this option. ๐ซ--recover,-rโ a repair that can fix almost any problem, except unique keys that aren't unique (which is an extremely unlikely error with MyISAM tables). if you want to recover a table, this is the option to try first. you should only try--safe-recoverifmyisamchktells you the table can't be recovered using--recover. (and in the unlikely case that--recoverfails, the data file stays intact โ so that's something.) if you've got lots of memory, bump up the value ofsort_buffer_size.--safe-recover,-oโ a repair using an old recovery method that reads through all rows in order and updates all the index trees based on the rows it finds. this is an order of magnitude slower than--recover, but it can handle a couple of very unlikely cases that--recovercan't. this method also uses way less disk space than--recover. normally you repair first with--recover, and then with--safe-recoveronly if--recoverfails. if you've got lots of memory, bump up the value ofkey_buffer_size.--set-collation=nameโ specify the collation to use for sorting table indexes. the character set name is implied by the first part of the collation name. iykyk.--sort-recover,-nโ forcesmyisamchkto use sorting to resolve the keys, even if the temporary files would be very, very large. ๐ญ--tmpdir=path,-t pathโ the path of the directory used for storing temporary files. if this isn't set,myisamchkfalls back to the value of theTMPDIRenvironment variable.tmpdircan also be set to a list of directory paths, used successively in round-robin fashion for creating temporary files. the separator character between directory names is the colon (:) on Unix and the semicolon (;) on Windows, NetWare, and OS/2.--unpack,-uโ unpacks a table that was packed withmyisampack. ๐
๐ OTHER MYISAMCHK OPTIONS ๐
these are the options for everything that isn't a table check or a repair. side quests, but make them main character energy ๐
--analyze,-aโ analyzes the distribution of key values. this improves join performance by letting the join optimizer better choose the order in which to join the tables and which indexes it should use. to get info about the key distribution, use amyisamchk --description --verbose tbl_namecommand or theSHOW INDEX FROM tbl_namestatement.--block-search=offset,-b offsetโ finds the record that a block at the given offset belongs to.--description,-dโ prints some descriptive info about the table. specifying--verboseonce or twice produces additional info. see the section called "MYISAMCHK TABLE INFORMATION". โจ--set-auto-increment[=value],-A[value]โ forcesAUTO_INCREMENTnumbering for new records to start at the given value (or higher, if there are existing records withAUTO_INCREMENTvalues this large). ifvalueisn't specified,AUTO_INCREMENTnumbers for new records begin with the largest value currently in the table, plus one.--sort-index,-Sโ sorts the index tree blocks in high-low order. this optimizes seeks and makes table scans that use indexes faster. ๐ฅ--sort-records=N,-R Nโ sorts records according to a particular index. this makes your data much more localized and may speed up range-basedSELECTandORDER BYoperations that use this index. (the first time you use this option to sort a table, it may be very slow. ๐) to determine a table's index numbers, useSHOW INDEX, which displays a table's indexes in the same order thatmyisamchksees them. indexes are numbered beginning with1.
if keys are not packed (PACK_KEYS=0), they have the same length, so when myisamchk sorts and moves records, it just overwrites record offsets in the index. if keys are packed (PACK_KEYS=1), myisamchk must unpack key blocks first, then re-create indexes and pack the key blocks again. (in this case, re-creating indexes is faster than updating offsets for each index.)
--stats-method=nameโ specifies how the index statistics collection code should treatNULLs. the possible values ofnameare"nulls_unequal"(the default),"nulls_equal"(which emulates MySQL 4 behavior), and"nulls_ignored".
๐ MYISAMCHK TABLE INFORMATION ๐
want the tea on a MyISAM table, or stats about it? use the commands below bestie. the output from these commands is explained later in this section.
myisamchk -d tbl_nameโ runsmyisamchkin "describe mode" to produce a description of your table. if you start the MariaDB server with external locking disabled,myisamchkmay report an error for a table that gets updated while it runs. but โ becausemyisamchkdoesn't change the table in describe mode, there's no risk of destroying data. phew ๐ซถmyisamchk -dv tbl_nameโ adding-vrunsmyisamchkin verbose mode so it produces more info about the table. adding-va second time produces even more info.myisamchk -eis tbl_nameโ shows only the most important information from a table. this one's slow though, because it has to read the entire table. ๐ฎโ๐จmyisamchk -eiv tbl_nameโ just like-eis, but it also tells you what's being done.
the tbl_name argument can be either the name of a MyISAM table or the name of its index file, as described in myisamchk(1). multiple tbl_name arguments can be given.
so, suppose a table named person has this structure. (the MAX_ROWS table option is in there so that in the example output from myisamchk shown later, some values are smaller and fit the output format more easily.)
CREATE TABLE person
(
id INT NOT NULL AUTO_INCREMENT,
last_name VARCHAR(20) NOT NULL,
first_name VARCHAR(20) NOT NULL,
birth DATE,
death DATE,
PRIMARY KEY (id),
INDEX (last_name, first_name),
INDEX (birth)
) MAX_ROWS = 1000000;
and suppose the table also has these data and index file sizes:
-rw-rw---- 1 mysql mysql 9347072 Aug 19 11:47 person.MYD
-rw-rw---- 1 mysql mysql 6066176 Aug 19 11:47 person.MYI
example of myisamchk -dvv output:
MyISAM file: person
Record format: Packed
Character set: latin1_swedish_ci (8)
File-version: 1
Creation time: 2009-08-19 16:47:41
Recover time: 2009-08-19 16:47:56
Status: checked,analyzed,optimized keys
Auto increment key: 1 Last value: 306688
Data records: 306688 Deleted blocks: 0
Datafile parts: 306688 Deleted data: 0
Datafile pointer (bytes): 4 Keyfile pointer (bytes): 3
Datafile length: 9347072 Keyfile length: 6066176
Max datafile length: 4294967294 Max keyfile length: 17179868159
Recordlength: 54
table description:
Key Start Len Index Type Rec/key Root Blocksize
1 2 4 unique long 1 99328 1024
2 6 20 multip. varchar prefix 512 3563520 1024
27 20 varchar 512
3 48 3 multip. uint24 NULL 306688 6065152 1024
Field Start Length Nullpos Nullbit Type
1 1 1
2 2 4 no zeros
3 6 21 varchar
4 27 21 varchar
5 48 3 1 1 no zeros
6 51 3 1 2 no zeros
explanations for the types of information myisamchk produces are given here. "Keyfile" refers to the index file. "Record" and "row" are synonymous, as are "field" and "column."
the initial part of the table description contains these values:
MyISAM fileโ name of the MyISAM (index) file.Record format- The format used to store table rows โ the examples above are living in
Fixed length. Other possible values areCompressedandPacked. (And just so you know,Packedis literally the thingSHOW TABLE STATUScallsDynamic.) - Chararacter set โ the table's default character set.
- File-version โ the version of the MyISAM format. Currently it is always
1. That's it. That's the number. - Creation time โ when the data file was created.
- Recover time โ when the index/data file was last reconstructed.
- Status โ the table status flags. The possible values are
crashed,open,changed,analyzed,optimized keys, andsorted index pages. - Auto increment key, Last value โ the key number tied to the table's
AUTO_INCREMENTcolumn, plus the most recently generated value for that column. Heads up though: these fields do not appear at all if there is no such column. - Data records โ how many rows are in the table.
- Deleted blocks โ how many deleted blocks are still out here holding onto reserved space. You can optimize your table to minimize this space. See Section 6.6.4, โMyISAM Table Optimizationโ.
- Datafile parts โ for dynamic-row format, this tells you how many data blocks exist. For an optimized table with no fragmented rows, this is the same as Data records.
- Deleted data โ how many bytes of unreclaimed deleted data are hanging around. Again, you can optimize your table to minimize this space. See Section 6.6.4, โMyISAM Table Optimizationโ.
- Datafile pointer โ the size of the data file pointer, in bytes. Usually it's
2,3,4, or5bytes. Most tables get by with2bytes, but ngl you can't control this from MariaDB yet. For fixed tables this is a row address. For dynamic tables this is a byte address. - Keyfile pointer โ the size of the index file pointer, in bytes. Usually
1,2, or3bytes. Most tables manage with2bytes, but MariaDB calculates this one automatically. It's always a block address. - Max datafile length โ how long the table data file can become, in bytes.
- Max keyfile length โ how long the table index file can become, in bytes.
- Recordlength โ how much space each row takes, in bytes.
Okay so the table description part of the output also spills the full list of every key in the table, and for each key, myisamchk shows you some low-key high-detail info:
- Key โ this key's number. It's only shown for the first column of the key. If it's missing, that line is the second or later column of a multiple-column key. For the table in the example, there are two table description lines for the second index, which tells you it's a multiple-part index with two parts.
- Start โ where in the row this portion of the index starts.
- Len โ how long this portion of the index is. For packed numbers, this should always be the full length of the column. For strings, it may be shorter than the full length of the indexed column, because you can index a prefix of a string column. The total length of a multiple-part key is the sum of the
Lenvalues for all the key parts. - Index โ whether a key value can exist multiple times in the index. Possible values are
uniqueormultip.(multiple). - Type โ what data type this portion of the index has. It's a MyISAM data type, and the possible values are
packed,stripped, orempty. - Root โ the address of the root index block.
- Blocksize โ the size of each index block. By default this is
1024, but the value may be changed at compile time when MariaDB is built from source. - Rec/key โ a statistical value used by the optimizer. It tells you how many rows there are per value for this index. A unique index always has a value of
1. This may be updated after a table is loaded (or greatly changed) withmyisamchk -a. And if it never gets updated at all, a default value of30is given.
The last chunk of the output serves up info about each column:
- Field โ the column number.
- Start โ the byte position of the column within table rows.
- Length โ the length of the column in bytes.
- Nullpos, Nullbit โ for columns that can be
NULL, MyISAM storesNULLvalues as a flag in a byte. Depending on how many nullable columns there are, one or more bytes can be used for this. TheNullposandNullbitvalues, if nonempty, tell you which byte and bit holds that flag indicating whether the column isNULL.
The position and number of bytes used to store NULL flags is shown on the line for field 1. Which is exactly why there are six Field lines for the person table even though it only has five columns. ๐
- Type โ the data type. The value may contain any of the following descriptors:
constantโ all rows have the same value.no endspaceโ do not store endspace.no endspace, not_alwaysโ do not store endspace and do not do endspace compression for all values.no endspace, no emptyโ do not store endspace. Do not store empty values.table-lookupโ the column was converted to anENUM.zerofill(N)โ the most significant N bytes in the value are always0and are not stored.no zerosโ do not store zeros.always zeroโ zero values are stored using one bit.
- Huff tree โ the number of the Huffman tree associated with the column.
- Bits โ the number of bits used in the Huffman tree.
The Huff tree and Bits fields only show up if the table has been compressed with myisampack. See myisampack(1) for an example of this information. โจ
Example of myisamchk -eiv output:
Checking MyISAM file: person
Data records: 306688 Deleted blocks: 0
- check file-size
- check record delete-chain
No recordlinks
- check key delete-chain
block_size 1024:
- check index reference
- check data record references index: 1
Key: 1: Keyblocks used: 98% Packed: 0% Max levels: 3
- check data record references index: 2
Key: 2: Keyblocks used: 99% Packed: 97% Max levels: 3
- check data record references index: 3
Key: 3: Keyblocks used: 98% Packed: -14% Max levels: 3
Total: Keyblocks used: 98% Packed: 89%
- check records and index references
*** LOTS OF ROW NUMBERS DELETED ***
Records: 306688 M.recordlength: 25 Packed: 83%
Recordspace used: 97% Empty space: 2% Blocks/Record: 1.00
Record blocks: 306688 Delete blocks: 0
Record data: 7934464 Deleted data: 0
Lost space: 256512 Linkdata: 1156096
User time 43.08, System time 1.68
Maximum resident set size 0, Integral resident set size 0
Non-physical pagefaults 0, Physical pagefaults 0, Swaps 0
Blocks in 0 out 7, Messages in 0 out 0, Signals 0
Voluntary context switches 0, Involuntary context switches 0
Maximum memory usage: 1046926 bytes (1023k)
myisamchk -eiv output includes the following information, bestie, let's go field by field:
- Data records โ the number of rows in the table.
- Deleted blocks โ how many deleted blocks still have reserved space. You can optimize your table to minimize this space. See Section 6.6.4, โMyISAM Table Optimizationโ.
- Key โ the key number.
- Keyblocks used โ what percentage of the keyblocks are used. When a table has just been reorganized with
myisamchk, the values are very high, like very near the theoretical maximum. Iconic behavior honestly. - Packed โ MariaDB tries to pack key values that share a common suffix. This can only be used for indexes on
CHARandVARCHARcolumns. For long indexed strings with similar leftmost parts, this can seriously reduce the space used. In the example above, the second key is40bytes long and a97%reduction in space is achieved. Slay. - Max levels โ how deep the B-tree for this key is. Large tables with long key values get high values.
- Records โ how many rows are in the table.
- M.recordlength โ the average row length. For tables with fixed-length rows this is the exact row length, because all rows have the same length.
- Packed โ MariaDB strips spaces from the end of strings. The
Packedvalue tells you the percentage of savings achieved by doing this. - Recordspace used โ what percentage of the data file is used.
- Empty space โ what percentage of the data file is unused.
- Blocks/Record โ the average number of blocks per row (that is, how many links a fragmented row is composed of). For fixed-format tables this is always
1.0. This value should stay as close to1.0as possible. If it gets too large, you can reorganize the table. See Section 6.6.4, โMyISAM Table Optimizationโ. - Recordblocks โ how many blocks (links) are used. For fixed-format tables, this is the same as the number of rows.
- Deleteblocks โ how many blocks (links) are deleted.
- Recorddata โ how many bytes in the data file are used.
- Deleted data โ how many bytes in the data file are deleted (unused).
- Lost space โ if a row is updated to a shorter length, some space is lost. This is the sum of all such losses, in bytes. ๐ญ
- Linkdata โ when the dynamic table format is used, row fragments are linked with pointers (
4to7bytes each).Linkdatais the sum of the amount of storage used by all such pointers.
๐ง โจ MYISAMCHK MEMORY USAGE โจ๐ง
Okay bestie, memory allocation is so important when you run myisamchk. Like, the whole vibe. myisamchk uses no more memory than its memory-related variables are set to. No cap. If you are going to use myisamchk on very large tables, you should first decide how much memory you want it to use. The default is to use only about 3MB to perform repairs. By using larger values, you can get myisamchk to operate faster. For example, if you have more than 32MB RAM, you could use options such as these (in addition to any other options you might specify):
shell> myisamchk --sort_buffer_size=16M \
--key_buffer_size=16M \
--read_buffer_size=1M \
--write_buffer_size=1M ...
Using --sort_buffer_size=16M should probably be enough for most cases. Lowkey iconic.
Be aware that myisamchk uses temporary files in TMPDIR. If TMPDIR points to a memory file system, out of memory errors can easily occur. If this happens, run myisamchk with the --tmpdir=path option to specify a directory located on a file system that has more space. Don't let TMPDIR betray you.
When performing repair operations, myisamchk also needs a lot of disk space:
- Twice the size of the data file (the original file and a copy). This space is not needed if you do a repair with
--quick; in this case, only the index file is re-created. This space must be available on the same file system as the original data file, as the copy is created in the same directory as the original. - Space for the new index file that replaces the old one. The old index file is truncated at the start of the repair operation, so you usually ignore this space. This space must be available on the same file system as the original data file.
- When using
--recoveror--sort-recover(but not when using--safe-recover), you need space on disk for sorting. This space is allocated in the temporary directory (specified byTMPDIRor--tmpdir=path). The following formula yields the amount of space required:
(largest_key + row_pointer_length) ร number_of_rows ร 2
You can check the length of the keys and the row_pointer_length with myisamchk -dv tbl_name (see the section called โMYISAMCHK TABLE INFORMATIONโ). The row_pointer_length and number_of_rows values are the Datafile pointer and Data records values in the table description. To determine the largest_key value, check the Key lines in the table description. The Len column indicates the number of bytes for each key part. For a multiple-column index, the key size is the sum of the Len values for all key parts.
If you have a problem with disk space during repair, you can try --safe-recover instead of --recover. Periodt.
๐ COPYRIGHT ๐
Copyright 2007-2008 MySQL AB, 2008-2010 Sun Microsystems, Inc., 2010-2025 MariaDB Foundation
This documentation is free software; you can redistribute it and/or modify it only under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License.
This documentation is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with the program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA or see http://www.gnu.org/licenses/.
๐ SEE ALSO ๐
For more information, please refer to the MariaDB Documentation, available online at https://mariadb.com/docs/
๐ AUTHOR ๐
MariaDB Foundation (http://www.mariadb.org/).
This page is from MariaDB 11.8, dated 5 March 2025, and it's literally MYISAMCHK(1) ๐ โจ
๐ฆ where this page comes from
- ubuntu stonking: mariadb-server 1:11.8.9+ds-4ubuntu2 ยท GPL-2.0-only
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms