mysqlcheck(1)
mysqlcheck checks, repairs, optimizes, and analyzes MySQL tables.
Synopsis
mysqlcheck [OPTIONS] [db_name [tbl_name ...]]Description
mysqlcheck is a table maintenance utility for MySQL databases. It can check tables for errors, repair corrupted tables, optimize table space usage, and analyze table statistics. It connects to a running MySQL server and performs operations on specified databases and tables.
If no database or table is specified, mysqlcheck operates on all databases and tables. The command can be run in various modes using different flags to perform different maintenance operations.
Common options
| Flag | What it does |
|---|---|
-u, --user=NAME | MySQL user name for authentication |
-p, --password[=PASSWORD] | MySQL password; prompts if no value given |
-h, --host=NAME | Connect to MySQL server on specified host |
-c, --check | Check tables for errors (default operation) |
-r, --repair | Repair corrupted tables |
-o, --optimize | Optimize tables by reorganizing data and index pages |
-a, --analyze | Analyze tables to generate key distribution statistics |
-A, --all-databases | Check all databases (default if no database specified) |
--databases | Check specified databases; treats all arguments as database names |
-q, --quick | Faster repair; skip row scanning to find bad rows |
-e, --extended | More thorough checking; perform full key lookup for each row |
--auto-repair | Automatically repair tables found to have errors |
Examples
Check all tables in the 'mydb' database; prompts for password
mysqlcheck -u root -p mydbCheck tables in all databases on the server
mysqlcheck -u root -p --all-databasesRepair the 'mytable' table in the 'mydb' database
mysqlcheck -u root -p -r mydb mytableOptimize all tables in the 'mydb' database
mysqlcheck -u root -p -o mydbAnalyze key distribution statistics for tables in 'mydb'
mysqlcheck -u root -p -a mydbPerform extended checking on all tables in 'mydb'
mysqlcheck -u root -p -c -e mydbCheck and automatically repair any corrupted tables in 'mydb'
mysqlcheck -u root -p -r --auto-repair mydbQuick repair of tables in 'mydb' without scanning rows
mysqlcheck -u root -p -q -r mydb