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

  • The Importance of Voice and Style in Essay Writing April 1, 2023
  • What Online Casinos Have No Deposit Bonus in Australia March 30, 2023
  • Four Foolproof Tips To Never Run Out Of Blog Ideas For Your Website March 28, 2023
  • The Interactive Entertainment Serving as a Tech Proving Ground March 28, 2023
  • Is it Good to Run Apache Web server and MySQL Database on Separate Cloud Servers? March 27, 2023

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, April 1, 2023, https://thecustomizewindows.com/2014/03/sql-commands-to-clean-wordpress-database-guide/.

Source:The Customize Windows, JiMA.in

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

We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept”, you consent to the use of ALL the cookies.
Do not sell my personal information.
Cookie SettingsAccept
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
CookieDurationDescription
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Functional
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytics
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Advertisement
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
Others
Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.
SAVE & ACCEPT