MyISAM
Tables
MyISAM
is the default table type in MySQL Version 3.23. It's
based on the ISAM
code and has a lot of useful extensions.
The index is stored in a file with the `.MYI' (MYIndex) extension,
and the data is stored in a file with the `.MYD' (MYData) extension.
You can check/repair MyISAM
tables with the myisamchk
utility. See section 4.4.6.7 Using myisamchk
for Crash Recovery. You can compress MyISAM
tables with
myisampack
to take up much less space.
See section 4.7.4 myisampack
, The MySQL Compressed Read-only Table Generator.
The following is new in MyISAM
:
MyISAM
file that indicates whether
the table was closed correctly. If mysqld
is started with
--myisam-recover
, MyISAM
tables will automatically be
checked and/or repaired on open if the table wasn't closed properly.
INSERT
new rows in a table that doesn't have free blocks
in the middle of the datafile, at the same time other threads are
reading from the table (concurrent insert). A free block can come from
an update of a dynamic length row with much data to a row with less data
or when deleting rows. When all free blocks are used up, all future
inserts will be concurrent again.
AUTO_INCREMENT
column. MyISAM
will automatically update this on INSERT/UPDATE
. The
AUTO_INCREMENT
value can be reset with myisamchk
. This
will make AUTO_INCREMENT
columns faster (at least 10%) and old
numbers will not be reused as with the old ISAM
. Note that when an
AUTO_INCREMENT
is defined on the end of a multi-part-key the old
behaviour is still present.
AUTO_INCREMENT
column) the key tree will be split so that the high node only contains one
key. This will improve the space utilisation in the key tree.
BLOB
and TEXT
columns can be indexed.
NULL
values are allowed in indexed columns. This takes 0-1
bytes/key.
myisamchk
.
myisamchk
will mark tables as checked if one runs it with
--update-state
. myisamchk --fast
will only check those
tables that don't have this mark.
myisamchk -a
stores statistics for key parts (and not only for
whole keys as in ISAM
).
myisampack
can pack BLOB
and VARCHAR
columns.
DATA/INDEX DIRECTORY="path"
option to
CREATE TABLE
). See section 6.5.3 CREATE TABLE
Syntax.
MyISAM
also supports the following things, which MySQL
will be able to use in the near future:
VARCHAR
type; a VARCHAR
column starts
with a length stored in 2 bytes.
VARCHAR
may have fixed or dynamic record length.
VARCHAR
and CHAR
may be up to 64K.
All key segments have their own language definition. This will enable
MySQL to have different language definitions per column.
UNIQUE
. This will allow
you to have UNIQUE
on any combination of columns in a table. (You
can't search on a UNIQUE
computed index, however.)
Note that index files are usually much smaller with MyISAM
than with
ISAM
. This means that MyISAM
will normally use less
system resources than ISAM
, but will need more CPU time when inserting
data into a compressed index.
The following options to mysqld
can be used to change the behaviour of
MyISAM
tables. See section 4.5.7.4 SHOW VARIABLES
.
Option | Description |
--myisam-recover=# | Automatic recovery of crashed tables. |
-O myisam_sort_buffer_size=# | Buffer used when recovering tables. |
--delay-key-write=ALL | Don't flush key buffers between writes for any MyISAM table |
-O myisam_max_extra_sort_file_size=# | Used to help MySQL to decide when to use the slow but safe key cache index create method. Note that this parameter is given in megabytes before 4.0.3 and in bytes beginning with this version. |
-O myisam_max_sort_file_size=# | Don't use the fast sort index method to created index if the temporary file would get bigger than this. Note that this parameter is given in megabytes before 4.0.3 and in bytes beginning with this version. |
-O bulk_insert_buffer_size=# | Size of tree cache used in bulk insert optimisation. Note that this is a limit per thread! |
The automatic recovery is activated if you start mysqld
with
--myisam-recover=#
. See section 4.1.1 mysqld
Command-line Options.
On open, the table is checked if it's marked as crashed or if the open
count variable for the table is not 0 and you are running with
--skip-external-locking
. If either of the above is true the following
happens.
If the recover wouldn't be able to recover all rows from a previous
completed statement and you didn't specify FORCE
as an option to
myisam-recover
, then the automatic repair will abort with an error
message in the error file:
Error: Couldn't repair table: test.g00pages
If you in this case had used the FORCE
option you would instead have got
a warning in the error file:
Warning: Found 344 of 354 rows when repairing ./test/g00pages
Note that if you run automatic recover with the BACKUP
option,
you should have a cron
script that automatically moves file with names
like `tablename-datetime.BAK' from the database directories to a
backup media.
See section 4.1.1 mysqld
Command-line Options.
MyISAM
Table FormatsMyISAM
Table ProblemsPosted by Andrea Dossena on Thursday September 12 2002, @2:18am | [Delete] [Edit] |
I'd like to understand why the storing of the data is a
machine and OS independent. I know that Intel
Machines stores data in RAM with the high byte first
viceversa Motorola Machines stores data with the
low one. Andrea
Posted by Byoung-In Han on Sunday December 1 2002, @7:03pm | [Delete] [Edit] |
Maximum key length is 500 bytes by default (can be
changed by recompiling). In cases of keys longer
than 250 bytes, a bigger key block size than the
default of 1024 bytes is used for this key.
how can i recompile to enlarge maximum key
length???
i want to create table like this...
create table test( field1 text not null,primary key
(field1(1024)) )
that is, i want primary key length to be more than
1024...
answer me... plz...ASAP
Posted by PRASANTH PISKA on Monday January 20 2003, @9:52pm | [Delete] [Edit] |
i think the documentation for this section should contain an overview on MyISAM tables which can give better idea of their usage. something similar to InnoDB tables overview
Posted by Tommy Tooth on Thursday May 22 2003, @4:45am | [Delete] [Edit] |
"Note that index files are usually much smaller with MyISAM than with ISAM. This means that MyISAM will normally use less system resources than ISAM, but will need more CPU time when inserting data into a compressed index."
Shouldn't the index be uncompressed for MyISAM as that would make it faster. I dont think disk space is much of a concern for me on a server, especially if it is few KB or MB.
Posted by Eric Redmond on Friday June 27 2003, @9:08am | [Delete] [Edit] |
Tommy - The data, however, must be read from the the disk. Disk reads are very slow. The less data read from the disk, the better. A few CPU cycles to [de]compress pales in comparison to the extra data being transfered to/from disk.