Defragment and Optimize MySQL and MariaDB Databases

If your MySQL or MariaDB install has been a bit sluggish, chances are your databases or tables are defragmented. This happens over time and is completely normal but causes MySQL or MariaDB to become slow as the software needs to located the information on the disk that is no longer close together. Just like a computer drive that has data fragmented over time, the same thing happens to databases. To fix this, we optimize and defragment the tables. This will move all the data so that it is closer together on the hard drives resulting in faster read and write times.

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!
  • 2 Users Found This Useful
Was this answer helpful?

Related Articles

Setup Your Own Private VPN with PPTP

PPTP VPN IntroductionTired of being geo blocked and not being able to watch your favorite TV...

Protect DirectAdmin from Brute Force Attacks

A common method of gaining access over a server is to use a technique called a brute force...

Changing Your Server's Time Zone

Changing the time zone that your server is set to is relatively simple and straight forward. In...

Synchronizing Your Server's Clock

Synchronizing your server's clock is not very difficult as there is a program that can be ran by...

Installing CSF (ConfigServer Security & Firewall)

The CSF, ConfigServer Security & Firewall, is a powerful firewall that is made for Linux...