$linuxjunkies
>

mysqlcheck(1)

mysqlcheck checks, repairs, optimizes, and analyzes MySQL tables.

UbuntuDebianFedoraArch

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

FlagWhat it does
-u, --user=NAMEMySQL user name for authentication
-p, --password[=PASSWORD]MySQL password; prompts if no value given
-h, --host=NAMEConnect to MySQL server on specified host
-c, --checkCheck tables for errors (default operation)
-r, --repairRepair corrupted tables
-o, --optimizeOptimize tables by reorganizing data and index pages
-a, --analyzeAnalyze tables to generate key distribution statistics
-A, --all-databasesCheck all databases (default if no database specified)
--databasesCheck specified databases; treats all arguments as database names
-q, --quickFaster repair; skip row scanning to find bad rows
-e, --extendedMore thorough checking; perform full key lookup for each row
--auto-repairAutomatically repair tables found to have errors

Examples

Check all tables in the 'mydb' database; prompts for password

mysqlcheck -u root -p mydb

Check tables in all databases on the server

mysqlcheck -u root -p --all-databases

Repair the 'mytable' table in the 'mydb' database

mysqlcheck -u root -p -r mydb mytable

Optimize all tables in the 'mydb' database

mysqlcheck -u root -p -o mydb

Analyze key distribution statistics for tables in 'mydb'

mysqlcheck -u root -p -a mydb

Perform extended checking on all tables in 'mydb'

mysqlcheck -u root -p -c -e mydb

Check and automatically repair any corrupted tables in 'mydb'

mysqlcheck -u root -p -r --auto-repair mydb

Quick repair of tables in 'mydb' without scanning rows

mysqlcheck -u root -p -q -r mydb

Related commands