Main menu:

Site search

Categories

Archive

How to optimize a table or database in mysql

If you are finding a lot of Long Running Queries and think you have built all the indexes you need.  You might want to try to optimize the database files.  As tables have inserts, the files can become less than optimized.
From the mysql manual…
shell> mysqlcheck [options] db_name [tables]

shell> mysqlcheck [options] –databases db_name1 [db_name2 db_name3…]

shell> mysqlcheck [options] –all-databases

If you do not name any tables following db_name or if you use the –databases or –all-databases option, entire databases are checked.

mysqlcheck has a special feature compared to other client programs. The default behavior of checking tables (–check) can be changed by renaming the binary. If you want to have a tool that repairs tables by default, you should just make a copy of mysqlcheck named mysqlrepair, or make a symbolic link to mysqlcheck named mysqlrepair. If you invoke mysqlrepair, it repairs tables.

The following names can be used to change mysqlcheck default behavior:

mysqlrepair The default option is –repair
mysqlanalyze The default option is –analyze
mysqloptimize The default option is –optimize

Write a comment