Home » Blogging Tips » Best WordPress SQL Queries to Make your WordPress Blog Faster

Best WordPress SQL Queries to Make your WordPress Blog Faster

Most of the professional bloggers are using Self Hosted WordPress Blog because it’s user friendly and has support for Plugins which simplifies the task of users. However, more use of Plugin makes a WordPress Blog heavy.  Page Load time always plays a major role in the success or failure of any Website. Now a day, everyone wants to visit fast loading site. A recent survey shows that a slow loading site lose almost 45% of its visitors. That’s probably the reason why, Good bloggers invests money on Premium Products like MaxCDN, Good Hosts etc. If you can invest money for making your WordPress Blog faster, I will highly recommend you MaxCDN.

If you don’t want to use any Plugin or Premium Products like MaxCDN, there is another way to make your WordPress Blog faster i.e through SQL Queries. WordPress stores every single information in MySQL Database, be it Posts, Comments, Pages, Plugins, Meta information etc. Most of the new WordPress users are unaware of the fact that, useless contents like post revision, drafts, trash etc. increases the database and thus affects the page load time of your blog. By removing these tables from your Database, You can make your wordPress blog faster.  This can be easily done by using “WordPress SQL Queries” in phpMyAdmin. In this post, I will show you the same.

1. Delete wp_postmeta values which are not attached to any Post

Whenever you install or remove any plugins in your wordPress blog, they store some data in Post Meta table i.e wp_postmeta. These data still remains inside the same table even after removing Plugins which unnecessarily increases the size of wordPress database and thus affects the page load speed. Use the below given code to delete Post Meta values which are not attached to any post.

If you want to optimize the wp_postsmeta, use the below given SQL code. It will decrease the size of your database and will make your site much faster.

2. Bulk Delete all Spam comments

If your wordPress blog has lots of Spam Comments, you will find it difficult to delete all comments manually. However, this can be easily done through SQL queries. Just use the below given SQL query and delete all spam comments at once.

Sometime, Bloggers may want to delete all Pending comments at once. If you want to perform this operation, use the below given code.

3. Bulk delete all Trash comments

Just like Spam comments, Trash comments are also captures useless space in your wordPress database. You can free up that space by using below given query.

4. Bulk delete all Pending Posts in WordPress

When you allow registration on your wordPress blog, people may write different kind of posts. Without your approval, they won’t be published but they will still consume space in your database. If you want to get rid of this, Use the below given query.

5. Delete draft and auto-draft at once

An unpublished article in wordPress mostly goes into Draft category. Sometime, draft contains only useless posts which can increase your database size. To delete drafts and auto-draft posts at once, use the below given SQL Query.

6. Delete Revision 

When you edit any article in WordPress, it automatically creates many revision copies and thus increase burden on your wordPress database. When revision entries are less in numbers, You can neglect them. However, if you have large number of revisions, i will recommend you to delete them using below given query.

 Source

7. Delete all PingBack data

If your articles are popular, they will receive large number of Pingback. It also increases the size of your database which affect your page load speed. You can reduce the size of database by removing all such pingbacks. To do so, use the below given query.

How to use SQL Queries in WordPress?
As I mentioned earlier, WordPress stores all kind of data in MySql database. You can run all kind of SQL queries using phpMyAdmin. If you are new, Follow below given instructions:
  • Log into your cPanel account.
  • Scroll down until you find “Databases” section. In this section, Click on “phpMyAdmin“.

phpMyAdmin option in cPanel

  • Now you will see your Database on left hand side. If you are using only one WordPress site under your hosting account, You will only see one Database file on left side. If you are using more than one wordPress site under your hosting account, You will see more than one databases. To find the correct database, check your “wp.config” file.
  • If you already know the name of your database, Click on it. You would be able to see all tables. Just click on “SQL” tab as shown in below given figure:

Using SQL queries in WordPress

 

  • After clicking on “SQL” tab as shown in above figure, You will be redirected to another page where you will see a Query box. You can write your SQL queries in this box. Once done, click on “Go” button to execute the query. An example for the same is shown below:

Use sql queries for making wordPress faster

 

  • After clicking on “Go” button, you will get a confirmation message. Just click on ok and your are done. Let’s have a look on below given image:

Using sql queries in wordPress

 

  • That’s it. You are done. Use the above provided queries and fasten your wordPress blog without using any Plugin or Premium Tool.
From the Editor’s Desk
Plugins are the power of WordPress. All above mentioned tasks can also be done by using various Plugins but they makes your wordPress blog slower. That’s probably the reason why, most of the professioal bloggers suggest you to use only necessary plugins. If any task can be easily done without using plugins, there is no need to use them(I guess). If you are completely new to WordPress and want to use a free self hosted blog, Check this tutorial.
Using all above mentioned WordPress SQL Queries, you can improve the page load speed of your blog. Just use them and let me know, How it worked for you. If you have any other suggestion or Question, let me know.
Genesis Framework for WordPress

About admin

Hi Guys. I am Ravi Kumar, the owner and Editor of this Blog. I am a Computer Science Engineer and a full time Blogger. I write articles on topics related to Blogging, SEO,Web designing,WordPress,Blogger,Content Marketing,Technology,CPA marketing and much more. However, My main aim is to help other bloggers. You can follow me on Twitter,Facebook and Google+

17 comments

  1. Hi Ravi,

    WordPress gives us lots of choices. There are loads of plugins to choose from, just to accomplish a single task! Well, this is both a boon and bane…ha ha..

    As you said, using too many plugins is not recommended. At the beginning of my blogging days, I was so intrigued by plugins that I used more plugins than it was necessary!

    Okay, let’s talk about the excellent info you have provided here. Keeping database clean is a good way of boosting loading speed. There are plugins to get this job done. But, the codes you provided will get this job done, without having to add an extra plugin!

    So, more work, but less load! These codes are handy, particularly for those who have some knowledge in coding and all. But you’ve provided screenshots too. This makes using these codes easy for even newbie bloggers!

    Useful post bro! :)

    Arun

  2. Hi Ravi,

    Thanks for sharing with us this insight. I have of course being experiencing a longer loading time recently and I guess it will be boiling to the loads of spam comments I have being receiving lately.

    I am of course going to implement what you’ve recommended.

  3. Hi Ravi,

    It’s good to have some insight knowledge about the database and tables used in WordPress. Thanks for the SQL commands to perform various tasks.

    At the same time, I’d like to know, why would anyone risk by accessing blog database directly when we already have plugins like ManageWP to do all these tasks from our WordPress Dashbaord? Do you think there is extra benefit using SQL method rather than plugin to manage all those tasks?

    • Plugins are helpful but sometime, they won’t work. For example- When i published this post, a wordpress user asked me to check his blog because it was taking too much time to load. In his admin panel, he was using “Wp-Optimize” plugin as well. His database size was around 1 GB. Plugin failed to work properly there. Whenever i tried to use it, blog started showing “Maintenance Mode”. I tried 2-3 plugins but still failed to fix his issue. At the end, I performed sql queries and fixed his issue………………so Plugins are useful but not everytime…but SQL queries will work everytime……and yes, it doesn’t affect your page load time as well…..ha ha
      admin recently posted…How I got 9000+ Email subscribers in less than 15 days and You can too?My Profile

  4. Hey mate,

     

    Thanks for sharing this. Yet to try this especially with thebpostmeta thingy.

     

    Appreciate it mate!

  5. It looks like a bit geeky article for me.  To be honest, as of now I don’t think I will be using it because my WordPress database is too small comparatively as my blog was newer one. However, this post may come handy for those who are troubling with their database space and wanted to speed up their blog

  6. Wow….thanks a lot for sharing this. We should always keep a check on the load speed of our blogs. It has become very much important, and you’ve provided a few best WP SQL Queries to handle taht with care…..Thanks again…

  7. Will there be any problem when accomplishing these tasks from php my admin panel ? i mean will it be a risk case ?

  8. This is a very good article that can help just about every WordPress site owner concerned about speed. Using sql queries are definitely easier than manually doing these one by one.

    But regarding the mass deleting all spam comments, it’s a good idea to first go through before doing that because there are usually a couple of genuine comments that get caught in the spam filters.

    Thanks to Piyush Mathur, for sharing this on Kingged.com. I found it helpful and have “kingged” it.

  9. i just move my wordpress site to new host and some plugins are not working . Please Ravi can you give a solution to it ?

  10. This indeed is a powerful tutorial, but it definitely not for newbies in wordpress coding and all.

    I would love my blog to load faster… faster and faster…..

    And am still working on it.
    frank joseph recently posted…The Ultimate Guide to Blogger Outreach and Guest BloggingMy Profile

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 class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

CommentLuv badge

Scroll To Top