How to optimize and clean WordPress database?

How to optimize WordPress and clean database? The easiest way, download WordPress WP-Optimize Plugin, activate and use it. The end… Nope, that’s not the end. Yes, WP-Optimize is a database cleanup and optimization tool. It doesn’t require PhpMyAdmin to optimize your database tables. And it allows you to remove post revisions, comments in the spam queue, un-approved comments within few clicks. But by using it is not enough, thanks to AllGuru.NET guide, it explains the detail to further delete orphan records in wp_term_relationships table.

DELETE FROM wp_term_relationships
WHERE NOT EXISTS (
SELECT * FROM wp_posts
WHERE wp_term_relationships.object_id = wp_posts.ID);

Note – do make a backup of your database before start executes any of WP-Optimize or manual delete tasks.

Above scripts are useful for those disabled the post revision function and want to clean up the orphan records that was not deleted by WP-Optimize. By the way, you can continue to clean wp_options table with WordPress Clean Options Plugin. But be warned, this plugin over cleaned my wp_options table. So use it carefully.