Back up your WordPress site before touching the database. That is the big rule. Your database holds posts, pages, users, settings, orders, comments, plugin data, and tiny bits of digital lint. Clean it the safe way, and your site can feel lighter. Clean it the reckless way, and you may delete something your site still needs. Nobody wants a “quick cleanup” that turns into a three-hour panic snack.
TLDR
Clean your WordPress database by making a backup, testing on staging, removing obvious junk, and optimizing tables after. For example, a blog with 320 posts may have 4,800 post revisions, 1,200 spam comments, and 900 expired transients. Removing that junk can cut database size by 20% to 40% on older sites. Use a trusted plugin or WP-CLI, and never delete data you do not understand.
Why Your WordPress Database Gets Messy
WordPress saves a lot. That is good. It also saves too much. That is less cute.
Every post edit can create a revision. Every plugin can add settings. Every spam comment gets stored until removed. Some plugins leave tables behind after you uninstall them. Honestly, it feels like cleaning a kitchen where the toaster keeps making crumbs after you unplug it.
Common database clutter includes:
- Post revisions from old drafts and edits.
- Auto drafts that were never published.
- Spam comments and trashed comments.
- Expired transients, which are temporary cached items.
- Orphaned metadata with no parent post, user, or comment.
- Unused plugin tables left behind by deleted plugins.
- Old logs from security, forms, backups, or ecommerce tools.
Step 1: Make a Real Backup
This step is not optional. Make a full backup of both your files and your database. A database-only backup is useful, but a full backup is safer.
Use your host backup panel, a trusted backup plugin, or a tool like phpMyAdmin. Download a copy if possible. Store it somewhere that is not the same server. If your server breaks, a backup stored only on that server is like keeping an umbrella inside a burning shed.
Before moving on, check this:
- Can you see the backup file?
- Do you know how to restore it?
- Is the backup from today?
- Does it include the database?
If the answer is no, stop. Fix that first.
Step 2: Use a Staging Site If You Can
A staging site is a private copy of your live site. It lets you test cleanup without scaring visitors. Many hosts offer one-click staging. Use it if you have it.
Run the cleanup there first. Then click around. Test forms. Test search. Test login. If you run a store, place a test order. Check product pages. Check checkout. Check emails.
It drives me crazy that some cleanup tools show “safe to delete” beside items that are only safe in some cases. A staging test catches those surprises before your real site starts acting weird.
Step 3: Remove the Easy Junk First
Start with the safe stuff. Do not begin with mystery tables. That is how trouble starts.
You can usually clean these with low risk:
- Spam comments
- Trashed comments
- Trashed posts and pages
- Expired transients
- Old auto drafts
- Excess post revisions
Post revisions are often the big one. If you edit a page 60 times, WordPress may save many versions. That is handy for recovery. It is not handy forever.
A good rule is to keep the latest 3 to 10 revisions per post. That gives you a safety net without keeping every typo from 2018.
Step 4: Pick the Right Tool
You have several good options. Choose based on your comfort level.
- Beginner: Use a cleanup plugin with clear checkboxes.
- Intermediate: Use your hosting database tools.
- Advanced: Use WP-CLI commands.
Popular cleanup plugins include tools that can remove revisions, spam, expired transients, and unused tables. Read each checkbox slowly. Do not click “select all” just because it looks satisfying. That button has chaos energy.
If you use WP-CLI, you can do tasks like deleting expired transients or optimizing database tables. This is fast. It is also very unforgiving. One typo can ruin your afternoon.
Step 5: Be Careful With Plugin Tables
Unused plugin tables can take up space. Some are safe to remove. Some are not. This is where many site owners get bitten.
A deleted plugin may leave tables behind. That does not always mean they are useless. You may reinstall that plugin later. Another plugin may read that data. A reporting tool may use old logs.
Be extra careful with tables related to:
- WooCommerce orders
- Membership data
- Learning course progress
- Form entries
- Booking records
- Security logs
- SEO plugin settings
When in doubt, leave it. A few extra megabytes are better than missing customer orders.
Step 6: Optimize the Tables
After deleting junk, optimize the database tables. Think of it as sweeping after clearing out boxes. It can help the database store data more neatly.
In phpMyAdmin, you may see an Optimize table option. Some plugins also offer database optimization. WP-CLI can do it too.
One small note. Many WordPress databases use InnoDB. With InnoDB, optimization may rebuild tables instead of shrinking them in the way you expect. That is normal. Do not panic if the size does not drop as much as you hoped.
Step 7: Check the Site After Cleanup
Do not clean and walk away. Test the site right away.
Check these areas:
- Homepage
- Blog posts
- Important landing pages
- Contact forms
- Admin login
- Search
- Checkout, if you sell products
- User account pages
Also check your speed. Use a simple tool before and after cleanup. Record the numbers. If your database was badly bloated, you may see faster admin screens and slightly better page generation times.
For example, a site admin page that took 2.8 seconds to load may drop to 1.9 seconds after clearing years of revisions and expired transients. Not magic. Just less junk to sort through.
Step 8: Prevent Future Mess
Cleaning once is nice. Keeping the database tidy is better.
Add this line to your wp-config.php file to limit revisions:
define('WP_POST_REVISIONS', 5);
You can also reduce autosave frequency:
define('AUTOSAVE_INTERVAL', 120);
That sets autosave to every 120 seconds. Use this with care. Autosaves can save your work during a browser crash.
Set a monthly cleanup reminder. For busy sites, use a weekly check. For small blogs, once every three months may be fine.
What Not to Do
Please do not open phpMyAdmin and start deleting rows because the names look “old.” WordPress data connects in odd ways. A post has metadata. Comments have metadata. Plugins may store settings in shared tables.
Avoid these risky moves:
- Deleting tables without checking which plugin created them.
- Cleaning a live site with no backup.
- Using abandoned cleanup plugins.
- Running SQL commands copied from random forum posts.
- Removing user data on membership or store sites.
If you are unsure, ask your host or a developer. Paying for 20 minutes of help is cheaper than rebuilding a broken shop.
A Simple Safe Cleanup Plan
Here is the easy version:
- Back up files and database.
- Test on staging if possible.
- Delete spam, trash, drafts, and expired transients.
- Limit old revisions instead of removing every revision.
- Review plugin tables with caution.
- Optimize tables after cleanup.
- Test the site after every major change.
- Set a schedule so the mess does not return.
A clean WordPress database is not about being perfect. It is about being safe, steady, and a little less annoyed every time the admin area loads. Start small. Keep backups. Read before you click. Your site will thank you with fewer hiccups and faster chores.

