Here is a simple command to auto repair, check and optimize all the tables in all databases running on a MySQL server:
mysqlcheck -u root -p --auto-repair --check --optimize --all-databases
mysqlcheck -u root -p --auto-repair --check --optimize --databases myDB
http://blog.taragana.com/index.php/archive/mysql-tip-how-to-check-repair...