Tuesday, September 4, 2007

Optimize MySQL table

OPTIMIZE TABLE should be used if you have deleted a large part of a table or if you have made many changes to a table with variable-length rows (tables that have VARCHAR, VARBINARY, BLOB, or TEXT columns).
For Sakai database the largest table is CONTENT_RESOURCE_BODY_BINARY.MYI
It keeps all files uploaded to Resources Tool. After deleting some files from Resources this table might be fragmented. To optimize its internal structure it's possible to use a mysql command:
optimize table CONTENT_RESOURCE_BODY_BINARY;
or mysql utility:
myisamchk -r --sort-index --analyze \
CONTENT_RESOURCE_BODY_BINARY.MYI
Option -o (--safe-recover) instead of -r should be used if there is an error:
myisamchk: error: sort_buffer_size is to small