• 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
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

  • Nginx WordPress Installation Guide (All Steps)

    This is a Full Nginx WordPress Installation Guide With All the Steps, Including Some Optimization and Setup Which is Compatible With WordPress DOT ORG Example Settings For Nginx.

  • Changing Data With cURL for OpenStack Swift (HP Cloud CDN)

    Changing Data With cURL For Object is Quite Easy in OpenStack Swift. Here Are Examples With HP Cloud CDN To Make it Clear. Official Examples Are Bad.

  • WordPress & PHP : Different AdSense Units on Mobile Devices

    Here is How To Serve Different AdSense Units on Mobile Devices on WordPress With PHP. WordPress Has Function Which Can Be Used In Free Way.

  • How to Export WordPress MySQL Database on Rackspace Deployment

    How to Export WordPress MySQL Database on Rackspace Deployment Where You Have Only Command Line Option and Ports are Blocked for Security?

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 (24.3K 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

  • Hybrid Multi-Cloud Environments Are Becoming UbiquitousJuly 12, 2023
  • Data Protection on the InternetJuly 12, 2023
  • Basics of BJT TransistorJuly 11, 2023
  • What is Confidential Computing?July 11, 2023
  • How a MOSFET WorksJuly 10, 2023
PC users can consult Corrine Chorney for Security.

Want to know more about us?

Read Notability and Mentions & Our Setup.

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

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