MYISAMCHK(1)

๐Ÿ“ฆ version 11.8.9, in ubuntu stonking

๐Ÿ’– 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 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 running myisamchk. the most effective means of doing so is to shut down the MariaDB server while running myisamchk, or to lock all tables that myisamchk is 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 typical debug_options string 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 -s twice (-ss) to make myisamchk very silent. ๐Ÿคซ
  • --verbose, -v โ€” Verbose mode. Prints more info about what the program is doing. Works with -d and -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 running mariadbd with external locking disabled, the table can only be locked by another myisamchk command. ๐Ÿ’€
  • --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 โ€” 9
  • ft_max_word_len โ€” version-dependent
  • ft_min_word_len โ€” 4
  • ft_stopword_file โ€” built-in list
  • key_buffer_size โ€” 523264
  • key_cache_block_size โ€” 1024
  • myisam_block_size โ€” 1024
  • read_buffer_size โ€” 262136
  • sort_buffer_size โ€” 2097144
  • sort_key_blocks โ€” 16
  • stats_method โ€” nulls_unequal
  • write_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, or TEXT columns, 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-recover option.

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, myisamchk or myisamchk --medium-check should 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 --recover or -r option. 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-check operation. 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 as mariadbd when run with external locking disabled. ๐Ÿ™ˆ
  • --update-state, -U โ€” Stores information in the .MYI file to indicate when the table was checked and whether the table crashed. This should be used to get full benefit of the --check-only-changed option, but you shouldn't use this option if the mariadbd server 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 .MYD file, saved as file_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 --quick for 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 like tbl_name.TMD) instead of just aborting. and if you add another --force on top, you dodge 'myisam_sort_buffer_size is too small' errors. in that case it'll try the repair with whatever myisam_sort_buffer_size you gave it and dynamically allocate as many management buffers as it needs. iconic.
  • --keys-used=val, -k val โ€” for myisamchk, 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 of 0 disables updates to all indexes, which you can use to get faster inserts. and deactivated indexes? you can bring them back with myisamchk -r. ๐Ÿ’ซ
  • --max-record-length=len โ€” skips rows bigger than the length you give, for when myisamchk can't allocate the memory to hold them.
  • --parallel-recover, -p โ€” uses the same technique as -r and -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 force myisamchk to 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-recover if myisamchk tells you the table can't be recovered using --recover. (and in the unlikely case that --recover fails, the data file stays intact โ€” so that's something.) if you've got lots of memory, bump up the value of sort_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 --recover can't. this method also uses way less disk space than --recover. normally you repair first with --recover, and then with --safe-recover only if --recover fails. if you've got lots of memory, bump up the value of key_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 โ€” forces myisamchk to 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, myisamchk falls back to the value of the TMPDIR environment variable. tmpdir can 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 with myisampack. ๐ŸŽ€

๐ŸŒˆ 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 a myisamchk --description --verbose tbl_name command or the SHOW INDEX FROM tbl_name statement.
  • --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 --verbose once or twice produces additional info. see the section called "MYISAMCHK TABLE INFORMATION". โœจ
  • --set-auto-increment[=value], -A[value] โ€” forces AUTO_INCREMENT numbering for new records to start at the given value (or higher, if there are existing records with AUTO_INCREMENT values this large). if value isn't specified, AUTO_INCREMENT numbers 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-based SELECT and ORDER BY operations 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, use SHOW INDEX, which displays a table's indexes in the same order that myisamchk sees them. indexes are numbered beginning with 1.

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 treat NULLs. the possible values of name are "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 โ€” runs myisamchk in "describe mode" to produce a description of your table. if you start the MariaDB server with external locking disabled, myisamchk may report an error for a table that gets updated while it runs. but โ€” because myisamchk doesn't change the table in describe mode, there's no risk of destroying data. phew ๐Ÿซถ
  • myisamchk -dv tbl_name โ€” adding -v runs myisamchk in verbose mode so it produces more info about the table. adding -v a 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 are Compressed and Packed. (And just so you know, Packed is literally the thing SHOW TABLE STATUS calls Dynamic.)
  • 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, and sorted index pages.
  • Auto increment key, Last value โ€” the key number tied to the table's AUTO_INCREMENT column, 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, or 5 bytes. Most tables get by with 2 bytes, 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, or 3 bytes. Most tables manage with 2 bytes, 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 Len values for all the key parts.
  • Index โ€” whether a key value can exist multiple times in the index. Possible values are unique or multip. (multiple).
  • Type โ€” what data type this portion of the index has. It's a MyISAM data type, and the possible values are packed, stripped, or empty.
  • 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) with myisamchk -a. And if it never gets updated at all, a default value of 30 is 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 stores NULL values as a flag in a byte. Depending on how many nullable columns there are, one or more bytes can be used for this. The Nullpos and Nullbit values, if nonempty, tell you which byte and bit holds that flag indicating whether the column is NULL.

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 an ENUM.
    • zerofill(N) โ€” the most significant N bytes in the value are always 0 and 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 CHAR and VARCHAR columns. For long indexed strings with similar leftmost parts, this can seriously reduce the space used. In the example above, the second key is 40 bytes long and a 97% 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 Packed value 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 to 1.0 as 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 (4 to 7 bytes each). Linkdata is 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 --recover or --sort-recover (but not when using --safe-recover), you need space on disk for sorting. This space is allocated in the temporary directory (specified by TMPDIR or --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 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