• Home
  • Archive
  • Tools
  • Contact Us

The Customize Windows

Technology Journal

  • Cloud Computing
  • Computer
  • Digital Photography
  • Windows 7
  • Archive
  • Cloud Computing
  • Virtualization
  • Computer and Internet
  • Digital Photography
  • Android
  • Sysadmin
  • Electronics
  • Big Data
  • Virtualization
  • Downloads
  • Web Development
  • Apple
  • Android
Advertisement
You are here: Home » SQL Commands to Clean WordPress Database : Guru Killer Guide

By Abhishek Ghosh March 25, 2014 2:52 am Updated on March 25, 2014

SQL Commands to Clean WordPress Database : Guru Killer Guide

Advertisement

Here is a Guru Killer Guide With the Excellent SQL Commands to Clean WordPress Database Which can Reduce the Database Size Up To 80% – Yes. All of us know almost everything, but there are things which can make you jump – read the guide on Indispensable MySQL queries for custom fields in WordPress.

At that time, that article was the most mentioned guide from this website, notably WordPress related almost all websites mentioned it and as a novice we got hacked via that particular page. We had no practical idea about SQL Injection. The article on MySQL Queries was like a Guru, but who did it was the Guru Killer. Today, there is not a single comment and ping back is present. One must be aware of the vulnerability of using Cache Plugins and WordPress comment form. Actually, Fetching Data from MySQL via PHP in WordPress is not very difficult.

Before we move towards coding part of this guide on SQL Commands to Clean WordPress Database, we must give you some links to increase your knowledge. On the lighter side, after many years; I wrote a blog my personal blog site – Life is MySQL Database Where One Can Not Run Queries.

Advertisement

---

 

SQL Commands to Clean WordPress Database : Know Something More Before You Clean Up !

 

We can not expect that a newbie will read this guide and apply them, it is per se quite dangerous. There is WordPress Plugin named WP DB Backup – it takes backup via WordPress Administration Panel – you must use it it to backup the database first. We have noticed, even if direct backup through PHPMyAdmin or Command Line Fails (yes!), this Plugin reliably work – only keep the settings to save the database on FTP.

We have shown how to do a Repairing Job of WordPress Database. It is not that, everyone is used with WordPress or may be not used with the basics – so, it is better to know what is SQL, what is MySQL, what is phpMyAdmin etc. Also know, there is noSQL Database like PostgreSQL. Yes, with modification, it is possible to run WordPress with PostgreSQL instead of MySQL – we do not want to go towards that topic.

For various reasons, usually due to our previously installed Plugins, Spams etc. our Database grows up and get filled up with non useful lines. Not only the size of database increases, it actually creates a big issue – it becomes very difficult to take a full backup. Many plugins, unfortunately mess-up the wp_postmeta Table.

 

SQL Commands to Clean WordPress Database

 

WP Optimize like plugins works for less for the result we want. As there are many users who has lesser idea about handling PHPMyAdmin; we will suggest to read this article – Remove WordPress Plugin From Database and watch the video embedded below.

wp_commentmeta Table

We already wrote how to reduce WP_commentmeta Table Database size in WordPress, there is also a PHP tweak for Akismet for solving the issue; this probably happens due to JSON based API issue, the database do not allow to delete what should be deleted, unfortunately the hacked version / modes version of PHP gets replaced when Akismet is updated. Not all part of Akismet is fully Open – the trick will work forever till WordPress changes their database type.

SQL Commands to Clean WordPress Database

wp_postmeta Table

This is here :

Vim
1
2
3
4
SELECT *
FROM wp_postmeta pm
LEFT JOIN wp_posts wp ON wp.ID = pm.post_id
WHERE wp.ID IS NULL

Not tested version (do not run without backup) :

Vim
1
2
3
4
5
SELECT * FROM wp_postmeta
WHERE NOT EXISTS (
SELECT * FROM wp_posts
WHERE wp_postmeta.post_id = wp_posts.ID
);

wp_posts Table

Probably you will never need it, still :

Vim
1
2
3
4
5
SELECT *
FROM {$wpdb->postmeta} as pm
LEFT JOIN {$wpdb->posts} as p
  ON pm.post_id = p.ID
WHERE p.ID IS NULL

DO NOT RUN the above without knowing what you are going to do.

Others

These are more than enough, but if a certain plugin still have data in specific Table; this is the way to clean up :

Vim
1
2
SELECT option_value FROM wp_options
  WHERE option_name = 'plugin_databasename' LIMIT 1

You must open the Table and select via GUI to clean the overhead. SQL command to optimize all the Tables :

Vim
1
OPTIMIZE TABLE `wp_commentmeta`, `wp_comments`, `wp_links`, `wp_options`, `wp_postmeta`, `wp_posts`, `wp_terms`, `wp_term_relationships`, `wp_term_taxonomy`, `wp_usermeta`, `wp_users`

Tagged With greatel7 , secreturp , wordpress database commands

This Article Has Been Shared 275 Times!

Facebook Twitter Pinterest
Abhishek Ghosh

About Abhishek Ghosh

Abhishek Ghosh is a Businessman, Surgeon, Author and Blogger. You can keep touch with him on Twitter - @AbhishekCTRL.

Here’s what we’ve got for you which might like :

Articles Related to SQL Commands to Clean WordPress Database : Guru Killer Guide

  • List of CMS without Database

    List of CMS without Database features some Free Software and some proprietary CMS which can serve the basic purpose of using a CMS – managing the contents.

  • Adding Schema.org Structured Data in Genesis Theme

    Adding Schema.org Structured Data in Genesis Theme without using any plugin is quite easy as Genesis has great documentation and has excellent existing markups.

  • Twitter Bootstrap Guide For Newbies

    Twitter Bootstrap guide is written in a way, so that the basic users can use Free Twitter Bootstrap Source Code and use customize for own website design.

  • WordPress Post to Downloadable PDF, Text : Practical Options

    WordPress Post to downloadable PDF, Text has many points to consider when we will think about the usability, SEO, HTML5 and Schema.org markups.

  • Guide to Image in CSS to Base64 Data URI Encoding

    Guide to image in CSS to Base64 Data URI encoding shows you how to change from background image CSS to data to reduce page loading time.

Additionally, performing a search on this website can help you. Also, we have YouTube Videos.

Take The Conversation Further ...

We'd love to know your thoughts on this article.
Meet the Author over on Twitter to join the conversation right now!

If you want to Advertise on our Article or want a Sponsored Article, you are invited to Contact us.

Contact Us

Subscribe To Our Free Newsletter

Get new posts by email:

Please Confirm the Subscription When Approval Email Will Arrive in Your Email Inbox as Second Step.

Search this website…

 

Popular Articles

Our Homepage is best place to find popular articles!

Here Are Some Good to Read Articles :

  • Cloud Computing Service Models
  • What is Cloud Computing?
  • Cloud Computing and Social Networks in Mobile Space
  • ARM Processor Architecture
  • What Camera Mode to Choose
  • Indispensable MySQL queries for custom fields in WordPress
  • Windows 7 Speech Recognition Scripting Related Tutorials

Social Networks

  • Pinterest (22.1K Followers)
  • Twitter (5.8k Followers)
  • Facebook (5.7k Followers)
  • LinkedIn (3.7k Followers)
  • YouTube (1.3k Followers)
  • GitHub (Repository)
  • GitHub (Gists)
Looking to publish sponsored article on our website?

Contact us

Recent Posts

  • Samsung Galaxy S22 Ultra: Long Term Review June 30, 2022
  • How to Make the Most of Your S Pen (S22 Ultra) June 29, 2022
  • Safe Chargers for Samsung Galaxy S22 Ultra June 27, 2022
  • How Telecoms Can Use The Cloud To Power Their 5G Network June 24, 2022
  • A Beginner Guide to Cloud Computing for Development June 22, 2022

About This Article

Cite this article as: Abhishek Ghosh, "SQL Commands to Clean WordPress Database : Guru Killer Guide," in The Customize Windows, March 25, 2014, July 1, 2022, https://thecustomizewindows.com/2014/03/sql-commands-to-clean-wordpress-database-guide/.

Source:The Customize Windows, JiMA.in

This website uses cookies. If you do not want to allow us to use cookies and/or non-personalized Ads, kindly clear browser cookies after closing this webpage.

Read Privacy Policy.

PC users can consult Corrine Chorney for Security.

Want to know more about us? Read Notability and Mentions & Our Setup.

Copyright © 2022 - The Customize Windows | dESIGNed by The Customize Windows

Copyright  · Privacy Policy  · Advertising Policy  · Terms of Service  · Refund Policy