MySQL check is a tool that gets installed along with installing MySQL database servers. It’s there to help analyze and fix common errors and optimize MySQL databases and tables.
The question is, how does one use the mysqlcheck command?
This brief post shows you how to use mysqlcheck to optimize, 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 a MySQL database client. It helps database administrators analyze, optimize and repair common issues in managing MySQL or MariaDB databases and tables.
Follow the steps below to see what you can do with this command.
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
Analyze 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
Optimize all databases
mysqlcheck -o --all-databases
Again, run the commands below if you set up a password on your database server.
mysqlcheck -o --all-databases -u username -p
Repair a particular database
mysqlcheck -r database_name
With the password on the database server, run the commands below
mysqlcheck -r database_name -u username -p
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 the table for errors.|
|-a, –analyze||Analyze the 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. This option considers all name arguments as database names, not 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. It may be used with –auto-repair to correct tables requiring version-dependent updates.|