Today we will see How to clean the database of our WordPress, because as time goes by it “fills up” with unnecessary data. In this blog about Black Hat we also teach you things about maintaining your website to make it go faster.

In the databases they “gather dust” or “extra data”, if you prefer. But the idea is that as the days, months and years go by while we are using WordPress, extra data accumulates, which in many cases takes up more than the necessary data. Today it’s time to clean up. I recommend doing this as it will improve the user experience of the website.
Before touching anything in the database, we need to make a backup.
But… what exactly is the Database?
WordPress is made up of two types of data. Files and databases:
- Files: The WordPress FTP files, themes, themes and files that we have uploaded (images, documents, videos, etc.).
- Data: The content of the website (the texts of the posts, of the pages, the titles of the products, their prices… everything we “write” and configure).
We do not see this Database in our FTP. Although it is normally hosted on the same server, we don’t have it there, visible. We must access it with a client program, like Sequel Pro, or an online manager, like PHPMyAdmin.

And why does it fill up with “useless” data?
By default WordPress stores a lot of information, which may be useful initially, but which in the long run we may never use again. For example, the recycle bin, SPAM comments, or even data from plugins that we have deleted and no longer use.
WordPress saves all of that as a precautionary measure. Maybe you want to recover that trash content, a SPAM comment that wasn’t, or even reinstall that plugin that you deleted.
How do I clean the database in WordPress?
The first thing is to install the WP-Sweep plugin. There are many (many, many) database cleaning plugins, but this is the one I recommend. The developer is very good, reliable, well known and even contributes to the core of WordPress. So 100% recommended.

Once installed and activated, go to “Tools / Sweep”. And there we will see everything that we can “sweep” in our database. I’m going to go through everything and summarize the most important, so you don’t delete anything you shouldn’t 😉
Cleaning up posts
We start with everything related to posts, pages, products and any other custom content.

The options it allows us to clean up are as follows:
- Old revisions of posts to be recovered.
- Auto-saved posts that we started to write and left halfway through without saving.
- Posts in the trash that we delete.
- Meta-information on deleted posts.
All of these can be deleted without a problem, unless we are not sure if we want to recover a post from the trash, or if we have auto-saved posts.
Cleaning up comments
Next we move on to comments. You know that content generated in WordPress can have comments from readers. Well, that also leaves a lot of “dust”:

The first row refers to unapproved comments – why keep them? Same with SPAM, deleted comments, as well as orphans, which are comments on a post that has been deleted.
Cleaning up users
Users are not spared either, as sometimes we still have information about them even if we delete them. This information is “meta-information” of users that no longer exist, i.e. data fields, such as name, phone number or twitter account. As we have deleted them, it doesn’t make much sense to have them there.
Cleaning transient options
Now we get more technical with transient options, which are options that are cached for a certain period of time.
We can delete them without any problems, although this may cause some collateral effect with users who are currently viewing the website, such as emptying their shopping cart, or they may be logged out and have to log in again. This will depend on each plugin.
In any case it is important to know that this cache of options is constantly being generated as people visit our site, and that they are very useful to avoid unnecessary calls to the database, and gain in speed.
Optimise WordPress database

This is a fixed “yes”, as the database tables will be optimised, relocating the information in a more efficient way. This can also be done from phpMyAdmin, but from here it is much simpler, just a click on the red button, and you are done.
Total database cleanup
This means that we will simply “sweep” or clean up all the options above. So if you are sure (very sure) of what you are doing, this is your button!
Just remind everyone that before using this plugin you should make a backup, as sometimes we don’t realise that deleting this data can cause unwanted side effects, until it’s too late.
Leave a Reply