To check and optimize tables of a MySQL database:
$> mysqlcheck -os <db_name> -u<username> -p
To achieve the same for all databases of the respective MySQL server you can run the following command:
$> mysqlcheck -Aos -u<username> -p
Further information about check and optimize tables in MySQL
To get a few more facts about how to check and optimize tables in MySQL, you should have a look at http://dev.mysql.com/doc/refman/5.7/en/mysqlcheck.html.