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
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 # repairOptions
| Flag | What it does |
|---|---|
| -c / --check | Check tables for errors (default) |
| -r / --repair | Repair (MyISAM/Archive only) |
| -a / --analyze | Update index statistics |
| -o / --optimize | Defragment / reclaim space |
| --all-databases | Process every database |
| --auto-repair | Repair 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.