This is a simple one liner to automatically check, repair and optimize all MySQL tables and all databases:
mysqlcheck -u root -p --auto-repair --check --optimize --all-databases
or
mysqlcheck -uda_admin -pgrep "^passwd=" /usr/local/directadmin/conf/mysql.conf | cut -d= -f2
--auto-repair --check --optimize --all-databases
Run it from command line or connect using SSH to your Linux/UNIX/BSD server.
If you just want to check/repair/optimize a single database and all its tables, use this command: mysqlcheck -u root -p DATABASE_NAME --auto-repair --check --optimize --all-databases
It maybe a good idea to flush your databases afterwards using:
mysql -uroot -p -e "FLUSH TABLES" or -mysql -uroot -p -e "FLUSH TABLES WITH READ LOCK"