Bug #19837 myisamchk doesn't return error status
Submitted: 16 May 2006 2:41 Modified: 16 May 2006 5:16
Reporter: Thiago Figueiro Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Command-line Clients Severity:S4 (Feature request)
Version:5.0.21-1 OS:Linux (RHEL4)
Assigned to: CPU Architecture:Any

[16 May 2006 2:41] Thiago Figueiro
Description:
Whenever an error is found in a table, myisamchk doesn't return an error code.

Case 1 (ok): error in the command line
# myisamchk -dsgfsdfds
myisamchk: unknown option '-g'
# echo $?
2

Case 2 (ok): no errors in the table
# myisamchk -s /var/lib/mysql/GTAS/simple
# echo $?
0

Case 3 (not ok): errors in the table but return status is 0
# myisamchk -s /var/lib/mysql/GTAS/simple
myisamchk: MyISAM file /var/lib/mysql/GTAS/simple
myisamchk: warning: 1 client is using or hasn't closed the table properly
MyISAM-table '/var/lib/mysql/GTAS/simple' is usable but should be fixed
# echo $?
0

Case 4 (not ok): errors in the table but return status is 0
# myisamchk -s /var/lib/mysql/GTAS/simple
myisamchk: MyISAM file /var/lib/mysql/GTAS/simple
myisamchk: warning: 1 client is using or hasn't closed the table properly
myisamchk: warning: Size of indexfile is: 1026          Should be: 1024
MyISAM-table '/var/lib/mysql/GTAS/simple' is usable but should be fixed
# echo $?
0

Case 5 (ok): error in the table and return status is not 0
# myisamchk -s /var/lib/mysql/GTAS/simple
myisamchk: Unknown error 126
myisamchk: error: '/var/lib/mysql/GTAS/simple' doesn't have a correct index definition. You need to recreate it before you can do a repair
# echo $?
1

How to repeat:
create database A;
use A;
create table simple (int a);

Case 4:
terminal 1: for i in `seq 1 2000`; do mysql -u root A -e "insert simple values ($i)"; echo $i; done
terminal 2: kill MySQL process while loop in terminal 1 is still running

Case 5:
Edit simple.MYI and insert 6 characters on byte position 29.

Suggested fix:
Return non zero status on all table errors - the utility itself says: "MyISAM-table '/var/lib/mysql/GTAS/simple' is usable but should be fixed"

Alternatively, return different status codes for different severities (i.e.: 1 -> run repair; 2 -> rebuild table)

The documentation doesn't mention anything about return codes either.
[16 May 2006 5:16] Valeriy Kravchuk
Looks like a reasonable feature request for me. Do you agree?