Herself's Webtools

Scripts, HowTos, Templates, Plugins, Widgets, Tips and Useful Information

Good WP database checks to run

with 2 comments

Every so often it’s good to just run a quick pass on your WordPress database and look for troubles.

There are two things I check for: users who don’t comment, and iframes and scripts inside of posts.

You can easily bookmark SQL queries in phpMyAdmin, I do this and try to run the scripts every week or so.

To check for iframes and scripts added to your posts log on to phpMyAdmin and then click the SQL tab and run the following command:


SELECT *
FROM wp_posts
WHERE post_content LIKE '%iframe%'
UNION
SELECT *
FROM wp_posts
WHERE post_content LIKE '%noscript%'
UNION
SELECT *
FROM wp_posts
WHERE post_content LIKE '%display:none%'
UNION
SELECT *
FROM wp_posts
WHERE post_content LIKE '%display:%'
UNION
SELECT *
FROM wp_posts
WHERE post_content LIKE '%ekibastos%'
UNION
SELECT *
FROM wp_posts
WHERE post_content LIKE '%visibility:hidden%';

This looks for hidden things in your posts. If you get any results back you should check that post very carefully for things you did not put in it.

Users who register and don’t comment are likely bots who got through the bot net, or spammers planning to come back later. I delete all users who register but don’t comment soon thereafter.

To check for users who haven’t commented run the following SQL query

SELECT user_login, user_email, date_format( user_registered, '%M %d %Y' ) AS user_registration_date
FROM wp_users
WHERE wp_users.user_login NOT
IN (
SELECT comment_author
FROM wp_comments
)
LIMIT 0 , 30

I’ve also begun checking comments for troubles using the same items I look for in posts:

SELECT *
FROM wp_comments
WHERE comment_content LIKE '%<iframe%'
UNION SELECT *
FROM wp_comments
WHERE comment_content LIKE '%<noscript%'
UNION SELECT *
FROM wp_comments
WHERE comment_content LIKE '%display:none%'
UNION SELECT *
FROM wp_comments
WHERE comment_content LIKE '%display:%'
UNION SELECT *
FROM wp_comments
WHERE comment_content LIKE '%ekibastos%'
UNION SELECT *
FROM wp_comments
WHERE comment_content LIKE '%visibility:hidden%'
LIMIT 0 , 30;

Another optimization you’ll want to make is to delete all those post revisions, they multiply quickly.

DELETE FROM wp_posts WHERE post_type = "revision";

And finally optimize your tables

OPTIMIZE TABLE `wp_comments` , `wp_links` , `wp_options` , `wp_postmeta` , `wp_posts` , `wp_terms` , `wp_term_relationships` , `wp_term_taxonomy` , `wp_usermeta` , `wp_users`;

Written by timestocome

September 13th, 2009 at 12:50 pm

Posted in mysql,security,wordpress

2 Responses to 'Good WP database checks to run'

Subscribe to comments with RSS

  1. hey admin

    i ran this query in my phpmyadmin and got this error on return


    Error

    SQL query:

    AND finally OPTIMIZE your TABLES OPTIMIZE TABLE `ugj_comments` , `ugj_links` , `ugj_options` , `ugj_postmeta` , `ugj_posts` , `ugj_terms` , `ugj_term_relationships` , `ugj_term_taxonomy` , `ugj_usermeta` , `ugj_users` ;

    MySQL said: Documentation
    #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'And finally optimize your tables

    OPTIMIZE TABLE `ugj_comments` , `ugj_links` ' at line 1

    sub0

    14 Dec 09 at 9:47 pm

  2. “AND finally optimize your tables” is not part of the SQL Sorry I didn’t make that clearer.

    It should be:

    OPTIMIZE TABLE `ugj_comments` , `ugj_links` , `ugj_options` , `ugj_postmeta` , `ugj_posts` , `ugj_terms` , `ugj_term_relationships` , `ugj_term_taxonomy` , `ugj_usermeta` , `ugj_users` ;

    timestocome

    15 Dec 09 at 8:58 am

Leave a Reply

You must be logged in to post a comment.