Posts Tagged ‘myisamchk’

MySQL: myisamchk

Monday, January 12th, 2015

Decided to get better knowledge of MySQL with crawling on http://dev.mysql.com/doc/refman/YOUR_VERSION/en/ , for example http://dev.mysql.com/doc/refman/5.7/en/ .

Before MySQL 5.5.5, MyISAM was the default storage engine. (The default was changed to InnoDB in MySQL 5.5.5.)
One of my deployments uses MySQL version prior to 5.5.5. While reading the documentation I found a nice utility, ‘myisamchk‘ and instantly decided to check with it one of *.MYI files. I was a little bit astonished when the utilite showed me some problems with one of files, while everything worked fine. This is the silent mode, only errors (if found) are showed:

root@zenwalk:~# myisamchk -s /var/lib/mysql/webapp/doityourself.MYI
myisamchk: MyISAM file /var/lib/mysql/webapp/doityourself.MYI
myisamchk: warning: 12 clients are using or haven't closed the table properly
MyISAM-table '/var/lib/mysql/webapp/doityourself.MYI' is usable but should be fixed

Normal mode:

root@zenwalk:~# myisamchk /var/lib/mysql/webapp/doityourself.MYI
Checking MyISAM file: /var/lib/mysql/webapp/doityourself.MYI
Data records:     170   Deleted blocks:       2
myisamchk: warning: 12 clients are using or haven't closed the table properly
- check file-size
- check record delete-chain
- check key delete-chain
- check index reference
- check data record references index: 1
- check data record references index: 2
- check record links
MyISAM-table '/var/lib/mysql/webapp/doityourself.MYI' is usable but should be fixed

So, let’s recover the .MYI file. Fire!

root@zenwalk:~# myisamchk --recover /var/lib/mysql/webapp/doityourself.MYI
- recovering (with sort) MyISAM-table '/var/lib/mysql/webapp/doityourself.MYI'
Data records: 170
- Fixing index 1
- Fixing index 2