Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Without having to script an 'optimize table' query to do all the databases/tables, we would like to run mysqlcheck --optimize --all-database instead.

What are the drawbacks of doing this through mysqlcheck; both would defragment the tables, correct?

share|improve this question
up vote 1 down vote accepted

mysqlcheck just runs a bunch of 'optimize table' SQL statements for you, so functionally they do the same thing.

Note that 'optimize table' for innodb just maps to an 'ALTER TABLE foo engine = innodb' statement. This rebuilds the entire table. Depending on the size of your table this may take a very long time, during which the table is locked and unavailable.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.