As root, run the following command to automatically optimize, repair, and defragment your MySQL or MariaDB tables and databases:
mysqlcheck -u <username> -p --auto-repair --optimize --all-databases
Be sure to replace <username> with the root username you installed MySQL as. You will be prompted for the password to enter securely so it is not available when running the history program. This command will work with any Linux system running either MySQL or MariaDB. If you are a enterprise managed VPS customer, Mean Servers does this procedure free of charge for you on request, just open a support ticket requesting a MySQL defragmentation!