MYSQL Optimize tables on Innodb in production environment advice

MySQL

According to mysqltunner.pl I have 177 Fragmented tables. I have over 5000 tables and 200 databases.

If I run optimize table on each of them, do you think I should take down the application to prevent reads and writes while I do this? I know that optimize locks the table, but if it is a pretty quick operation I don't know if it was cause any problems.

Best Answer

You can optimize a table without interrupting service by using pt-online-schema-change:

$ pt-online-schema-change --alter="ENGINE=InnoDB" --execute D=sakila,t=actor

Also, MySQL 5.6.17 supports OPTIMIZE as an online DDL change, allowing concurrent DML.