“If your business isn’t online, it doesn’t exist” was a common saying in the middle of the last decade. It was, is, and will be true, but it’s no longer enough. Nowadays, your business not only needs a website but it should load quickly on any mobile device. People aren’t patient enough to wait for your site to load. Improving loading speed is a WordPress user’s nightmare because it depends on many factors. Plus, improving speed often means reducing the complexity of the site. You need to find the sweet spot of functionality vs. loading-speed limitations.
In this context, no method of improving the loading speed can be neglected. You will find a plethora of guides in this respect, and many of them contain useful tricks. However, a vast majority of them miss an excellent method of reducing the loading time: optimizing the WordPress database correctly. Optimizing a database may sound daunting to less-experienced WordPress users. Stick with us, and let’s get our hands dirty with it.
During a standard WordPress installation, 12 tables are created to store necessary information about your website. Check out “Database Description” from WordPress Support to get an idea about each table. These tables store, amongst other things, blog posts, pages, comments, pingbacks, post revisions, and drafts.
Certainly, you will install plugins that will create other tables (e.g., one of my blogs has 46 tables). They store helpful and unhelpful information so you will need to get rid of useless data. Once you delete that bloating data, your WordPress databases will run faster, and as a result, your website will also load faster.
How to Optimize WordPress Databases
Prior heading to your databases, make a complete backup of your website. Don’t skip this part because any error could crash your entire site!
You have to access WordPress databases through PhpMyAdmin or a similar tool if your host doesn’t use cPanel. Select your database, and it will display all of your website’s tables. You can perform different actions for each table separately or collectively.
In our case, I suggest checking all your tables (PhpMyAdmin has a built-in option to check all tables) and select them to optimize. It may take a few seconds depending on your database size, and voila! You have optimized your website!
Tricks to Remove Worthless Data
Even though you have optimized the database, the game isn’t over. It will refill with garbage or useless data. Here are a few tricks that will help you reduce the bloat.
Revisions are genuine gold for bloggers because it’s so easy to ruin a post. In case of a disaster, you can load a revision and start working on that. WordPress doesn’t have a limitation regarding the number of revisions. It could have 30 revisions for a single post. Of course, these revisions aren’t all necessary, and they bloat the database.
Limit the number of revisions stored in your database. Head to your file manager, open up the wp-config.php file, and insert this line of code:
define( 'WP_POST_REVISIONS', 3 );
Now WordPress will save only the latest three revisions. Feel free to change the number of revisions to suit your needs.
WordPress autosaves your articles every 60 seconds. To avoid bloating the database, you can change this interval. Just go to the wp-config.php file and add the following line of code:
define( 'AUTOSAVE_INTERVAL', 240 );
Feel free to change the interval of time to suit your needs; the time is measured in seconds.
Your database bulks with trash because, by default, WordPress stores deleted items for 30 days. You can reduce this period to make your website run faster. As you have probably deduced, go to the wp-config.php file and add the following line of code:
define( 'EMPTY_TRASH_DAYS', 3 );
Feel free to change the trash-emptying interval to suit your needs.
Plugins to Optimize WordPress Database
You can optimize your WordPress database manually, but it’s inconvenient, and you have to remember to do it regularly. Instead, a plugin can do it regularly and even better than you can. Here are three top-notch suggestions:
1. WP Optimize
This plugin is the most frequently used for database optimization, and users rate it excellently. WP Optimize is user-friendly and can be utilized even by newbies. Once you install and activate it, you can perform table optimization and enable periodic cleanups.
This plugin does many other useful things such as removing unnecessary post revisions, deleting pingbacks and trackbacks, showing database stats, and it retains a set number of weeks the cleaned data.
This plugin is an alternative to WP Optimize. It performs any type of action on your database. WP-DBManager repairs, optimizes, and restores a database and drops or empties tables. It also lets you set up a periodic cleanup.
It’s almost impossible not to use a plugin for your WordPress site. The chances are that you have installed and deleted plugins, but you didn’t pay attention to the tables left in your database. Manually cleaning these tables is time-consuming, and you might delete useful data.
Plugins Garbage Collector plugin has an inspired name. It removes the tables created by deleted plugins so that the database will run faster.
What do you think – is that hard to optimize a WordPress database? Doing it manually is a little bit riskier than using a plugin because you could delete useful data. Using a plugin is safer, but installing a plugin slows down the loading speed of your site. Please let us know what you think about database optimization and which method is better for you. We are waiting for your input.