Skip to content
Latchkey

mysqlcheck: Usage, Options & Common CI Errors

mysqlcheck checks, repairs, analyzes, and optimizes MySQL tables from the shell.

mysqlcheck wraps CHECK/REPAIR/ANALYZE/OPTIMIZE TABLE so you can maintain tables without writing SQL. The gotcha is that REPAIR only works on certain engines, not InnoDB.

What it does

mysqlcheck connects to a server and runs maintenance on tables: checking for corruption, repairing (MyISAM/Archive), analyzing key distribution, and optimizing to reclaim space. It can target one table, a database, or all databases.

Common usage

Terminal
mysqladmin... ; mysqlcheck -h 127.0.0.1 -u root -psecret -c app
mysqlcheck -h 127.0.0.1 -u root -psecret -a app   # analyze
mysqlcheck -h db -u root -psecret -o --all-databases   # optimize all
mysqlcheck -h 127.0.0.1 -u root -psecret -r app sometable   # repair

Options

FlagWhat it does
-c / --checkCheck tables for errors (default)
-r / --repairRepair (MyISAM/Archive only)
-a / --analyzeUpdate index statistics
-o / --optimizeDefragment / reclaim space
--all-databasesProcess every database
--auto-repairRepair any table found corrupt

Common errors in CI

note : The storage engine for the table doesn't support repair - InnoDB tables cannot be REPAIRed by mysqlcheck; for InnoDB use OPTIMIZE (which it maps to a rebuild + ANALYZE) or restore from a dump. Access-denied errors are the usual -p/MYSQL_PWD issue. mysqlcheck prints status per table (status : OK) rather than failing loudly, so grep the output if a CI step must assert health.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →