Bug #43555 mysqlcheck exits 0 althought corruption found
Submitted: 11 Mar 2009 9:42 Modified: 11 Mar 2009 15:45
Reporter: Robert Heinzmann Email Updates:
Status: Verified Impact on me:
Category:MySQL Server: MyISAM storage engine Severity:S3 (Non-critical)
Version:4.0.27, 5.0.67, 5.0.80-bzr, 5.1 OS:Linux
Assigned to: CPU Architecture:Any
Tags: mysqlcheck

[11 Mar 2009 9:42] Robert Heinzmann
When removing a MyISAM INDEX file for a MyISAM table (simulate index corruption) and running mysqlcheck on that database, the return code of mysqlcheck is 0, althought the corruption is detected.

This makes it hard to use the mysqlcheck utility in batch routines like check like this, if that fails, check deeper etc.

The mysqlcheck return codes are not documentet in the man page, so this may be intended behaviour.

How to repeat:
---- o< -----
root@server# mysql -e "create database mysql_test_db;"
root@server# mysql -e "create table test (name varchar(255));" mysql_test_db;"
root@server# rm mysql_datadir/mysql_test_db/test.MYI
root@server# ls -1 mysql_datadir/mysql_test_db/*
root@server# mysqlcheck -serf --auto-repair mysql_test_db
Error    : Can't find file: 'test' (errno: 2)
error    : Corrupt
root@server# echo $?
---- o< -----

Suggested fix:
Modify mysqlcheck to return != 0 if not all errors could be fixed during the run.
[11 Mar 2009 15:45] Valeriy Kravchuk
Indeed, it returns exit code 0 for almost all cases (besides wrong options):

valeriy-kravchuks-macbook-pro:5.0 openxs$ bin/mysqlcheck --check test tmi
Error    : Can't find file: 'tmi' (errno: 2)
error    : Corrupt
valeriy-kravchuks-macbook-pro:5.0 openxs$ echo $?
valeriy-kravchuks-macbook-pro:5.0 openxs$ bin/mysqlcheck --HECK test tmi
bin/mysqlcheck: unknown option '--HECK'
valeriy-kravchuks-macbook-pro:5.0 openxs$ echo $?