8 Tips for Keeping a Squeaky Clean WordPress Database

February 23, 2010  | 
10 Comments

Optimizing your database is a necessary part of WordPress housekeeping. Things can start to pile up in there… post revisions, old spam comments, etc., and your blog can start to get sluggish. We’ve gathered a number of solid tips for getting your database into shape without having to be an expert.

Warning: Back up your database in case you screw up. Yes, people still need to be reminded to do this. I know you’ve heard the horror stories. ;)

Delete Post Revisions and their Meta Data

This is probably one of the biggest things that will clutter up your database, especially if you’ve had a blog running for a number of years. Clean them all out with this simple query:

DELETE a,b,c FROM wp_posts a WHERE a.post_type = 'revision' LEFT JOIN wp_term_relationships b ON (a.ID = b.object_id) LEFT JOIN wp_postmeta c ON (a.ID = c.post_id);

Source: http://www.onextrapixel.com/2010/01/30/13-useful-wordpress-sql-queries-you-wish-you-knew-earlier/

Delete All Pingbacks

Yes, even pingbacks get stored in your database. Clean them out in one quick query:

DELETE FROM wp_comments WHERE comment_type = 'pingback';

Source: http://www.onextrapixel.com/2010/01/30/13-useful-wordpress-sql-queries-you-wish-you-knew-earlier/

Delete All Spam Comments

If you’ve gotten a lot of spam comments, you don’t want those piling up in your database. Here’s a way to delete them all:

DELETE from wp_comments WHERE comment_approved = '0'LETE from wp_1_comments WHERE comment_approved = '0' 

Clean Out Unused Tags

This query will identify and remove tags that have been created but are unused in your WordPress blog:

SELECT * From wp_terms wt INNER JOIN wp_term_taxonomy wtt ON wt.term_id=wtt.term_id WHERE wtt.taxonomy='post_tag' AND wtt.count=0;

Source: http://www.catswhocode.com/blog/wordpress-10-life-saving-sql-queries

Disable All of Your Plugins

This query will help you to quickly disable all of your plugins so that you can do maintenance, determine the source of plugin conflicts, or upgrade your installation. This can be especially helpful if you have a lot of plugins in operation on your site.

UPDATE wp_options SET option_value = '' WHERE option_name = 'active_plugins';}

Source : http://www.wprecipes.com/how-to-disable-all-your-plugins-in-a-second

Remove Orphaned Options

WordPress uses the options table to store plugin settings and many internal settings. The Clean Options plugin will determine which options are orphaned – options that do not have any files that “get” their values. You will be able to view them and decide which ones you want to remove from the options table.

Determine Where Your Blog is Slowing Down

If your blog has been slowing down and you don’t know why, download the WP Tuner plugin and find what is causing it. This plugin operates as a performance analysis toolkit and you can customize it with hooks and specific requests for loading time information.

Don’t Get Your Hands Dirty – Let the Plugin Do It!

If using phpmyadmin scares you, then try WP-Optimize which will optimize your database in one click. It allows you to remove post revisions, comments in the spam queue, un-approved comments. It will also display database table statistics that show how much space can be optimzied and how much space has been cleared.

Give your WordPress site a little health check-up today and apply these tips to get it running faster. This post by no means covers all of the tools available to you, so if you’ve had a good experience with any other database optimization techniques, please share in the comments. Happy housekeeping!

Featured Plugin - Send beautiful html email newsletters, from WordPress!

Now there's no need to pay for a third party service to sign up, manage and send beautiful email newsletters to your subscriber base - this plugin has got the lot.
Find out more

Featured Plugin - Start Your Own Powerful Membership Site

If you're thinking about starting a paid, or just private, membership site then this is truly the plugin you've been looking for. Easy to use, massively configurable and ready to go out of the box!
Find out more

Featured Plugin - Turn any WordPress page into a fully featured wiki!

To get a wiki up and running you used to need to install Mediawiki and toil away for days configuring it... not any more! This plugin gives you *all* the functionality you want from a wiki, in WordPress!!!
Find out more

Featured Plugin - WordPress + Google Maps = Perfect

Simply insert google maps into posts, sidebars and pages - show directions, streetview, provide image overlays and do it all from a simple button and comprehensive widget.
Find out more

Featured Plugin - Start your own Quora / StackOverflow / Yahoo Q&A site

It's now incredibly easy to start your own Q&A site using nothing more than WordPress - The Q&A plugin simply and brilliantly transforms any site, or page, into a perfect support or Q&A environment.
Find out more

Featured Plugin - Add bottom corner (or anywhere else) chat to your site

No javascript required, no third part chat engine, just fully featured chat right in your own database on your own WP sites - couldn't be easier.
Find out more

Featured Plugin - Open an Online Store with MarketPress

Out of all the WordPress ecommerce plugins available, this has got to be the winner - easy to configure, powerful functionality, multiple gateways and more. A simply brilliant plugin!
Find out more

Featured Plugin - Host sites, get paid, just like WordPress.com

If you've ever wondered how you could offer a paid site management and hosting service, then this is the plugin for you. Offer a freemium or paid service, for any niche you like, it's powered Edublogs.org to success already!
Find out more

Featured Plugin - Every great SEO tweak you need, in one snazzy bundle

Fully integrated with the SEOMoz API, complete with automatic links, sitemaps and SEO optimization of your WordPress setup - this is the only plugin you need to help you rank your site number 1 on Google - nothing else compares.
Find out more

10 Responses to 8 Tips for Keeping a Squeaky Clean WordPress Database

  1. A great way to keep the post revisions under control all the time is to use the Revision Control Plugin.

    http://wordpress.org/extend/plugins/revision-control/

    It’ll just delete the revisions of posts as they get old enough. Most of my sites are set to 5 revisions only.

  2. Any idea if WP-Optimize is WPMU_2.9.1./BP_1.2 friendly?

    I am using Optimize DB (http://wordpress.org/extend/plugins/optimize-db) but am not sure if does anything more than what it says it does…optimize your database.

    So I may be looking to switch.

    As always, thanks for the great info.

  3. Pingback: How to keep your WP database squeaky clean

  4. Pingback: Wordpress Belarus » Blog Archive » 8 Tips for Keeping a Squeaky Clean WordPress Database – WordPress …

  5. As I was reading this, I was thinking…use WP Optimize! I’m glad you referenced it at the end. :)

  6. Pingback: 8 Tips for Keeping a Squeaky Clean WordPress Database - Free Wordpress Themes Daily

  7. Pingback: How to Backup and Import a Very Large WordPress MySQL Database - WordPress MU and BuddyPress plugins, themes, support, tips and how to's

  8. The SQL in the “Delete spam comments” box looks a little iffy.

    DELETE from wp_comments WHERE comment_approved = '0'LETE from wp_1_comments WHERE comment_approved = '0'

    would probably work better as

    DELETE from wp_comments WHERE comment_approved = '0'; DELETE from wp_{n}_comments WHERE comment_approved = '0'

    where {n} is the ID of the multisite site from the wp_blogs table.

  9. Ahh yeah you have the best list I have found.. We will for sure add your to our bookmarks.. Keep up the good work!

Click on a tab to select how you'd like to leave your comment

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Subscribe without commenting