To go through and optimise tables which have previously crashed, the following allows you to loop through only those which have crashed previously, and run the '-o' flag to optimise and repair the database.

This is significantly more efficient than running mysqlcheck -A -o, which can consume a huge amount of resource / time to complete (although, this is still recommend occasionally to improve the performance of your MySQL)

for db in $(cat /var/lib/mysql/mysql-error.log | grep crash | awk -F"/" '{print $2}' | sort | uniq); do mysqlcheck $db -o; done;
Did this answer your question?