MySQL check is a tool that gets installed along with installing MySQL database servers. It’s there to help analyze and fix common errors as well as optimize MySQL databases and tables.
The question is how does one use mysqlcheck command?
This brief post shows you how to use mysqlcheck to optimize and repair and fix common problems with MySQL databases.
Sometimes MySQL databases get corrupt or don’t function as efficiently as they should. These are just some of the problems you may find yourself trying to fix. In these situations, your first go-to tool should be mysqlcheck.
This tool comes with MySQL database client. It helps database administrators analyse, optimize and repair common issues found in managing MySQL or MariaDB databases and tables.
Follow the steps below to see what you can do with this command.
Step 1: Check all tables in a particular database
mysqlcheck -c database_name
If your database server has a password, use the command below.
mysqlcheck -c databse_name -u username -p
Step 2: Analyse all tables in a particular database
mysqlcheck -a database-name
If your database server has a password, run the commands below
mysqlcheck -a database_name -u username -p
Step 3: Optimize all databases
mysqlcheck -o --all-databases
Again, if you setup password on your database server, run the commands below.
mysqlcheck -o --all-databases -u username -p
Step 4: Repair a particular database
mysqlcheck -r database_name
With password on database server, run the commands below
mysqlcheck -r database_name -u username -p
Step 5: Optimize and Repair MySQL databases
mysqlcheck --auto-repair -o --all-databases
With username and password, run the commands below
mysqlcheck --auto-repair -o --all-databases -u username -p
A table to help you:
|-c, –check||Check table for errors.|
|-a, –analyze||Analyze given tables.|
|-o –optimize||Optimize the tables.|
|-r, –repair||Perform a repair that can fix almost anything except unique keys that are not unique.|
|–auto-repair||If a checked table is corrupted, automatically fix it. Repairing will be done after all tables have been checked.|
|-A, –all-databases||Check all the databases. This is the same as –databases with all databases selected.|
|-B, –databases||Process all tables in the named databases. With this option, all name arguments are regarded as database names, not as table names.|
|–tables||Overrides the –databases or -B option such that all name arguments following the option are regarded as table names.|
|-g, –check-upgrade||Check tables for version-dependent changes. May be used with –auto-repair to correct tables requiring version-dependent updates.|