WordPress MySQL Tables Analysis

Analyzing WordPress MySQL Tables

Notes from analyzing WordPress MySQL tables.

Shou Arisaka
2 min read
Oct 1, 2025

About the post_type Column

There are 'revision' and 'post'. Well, revisions are like backups, used when you want to revert to a previously written state. Revisions are basically unnecessary, so there are even plugins that prevent revisions from being generated. Therefore, this post_type column is basically post.

select * from wp_posts where post_type='post';

Overview of Each MySQL Table

# Display all posts (including revisions, etc.)
select * from wp_posts ;

# Display all posts
select * from wp_posts where post_type='post' ;

# Display only posts with 500 characters or less
select * from wp_posts where post_type='post' and char_length(post_content) < 500 ;

# Switch database
use yuis_fuumin2 ;
use yuis_yuisorgblog ;

# Posts: post/page, other
select * from wp_posts ;
select * from wp_links ;

# index/follow, other various meta information
select * from wp_postmeta;
select * from wp_options;

select * from wp_usermeta;
select * from wp_users;

SELECT NOW();

# Categories and tags and slug settings
select * from wp_terms;

# empty
select * from wp_termmeta;

# Divide terms into category or tag or other ยท Set category description
select * from wp_term_taxonomy;

# Add term_taxonomy_id=term_id to object_id=post_id here
select * from wp_term_relationships;
desc wp_term_relationships;

# Count posts
select count(*) from wp_posts ;

# Search and select with regular expressions
select id,post_status,post_date,post_title,post_content from wp_posts where post_title REGEXP'.*Ruby.*';

# meta: nofollow/noindex
# Use and
# Using & leads to disaster
update wp_postmeta set meta_value='foo' where post_id='102' and meta_key='index';
update wp_postmeta set meta_value='foo' where post_id='102' & meta_key='index';
update wp_postmeta set meta_value='bar' where post_id='102' and meta_key='follow';
update wp_postmeta set meta_value='bar' where post_id='102' & meta_key='follow';

# Basic update
update wp_posts
set
post_author='1',
guid='',
post_title='title',
post_name='title',
post_content='content!!',
post_type='post',
#post_status='publish',
post_status='private',
post_date=NOW(),
post_date_gmt=NOW(),
post_modified=NOW(),
post_modified_gmt=NOW()
#where id=80;
where post_title REGEXP'title' ;

desc wp_posts ;
show ;

# other

SELECT '1+2' REGEXP '^1\\+2';

Share this article

Shou Arisaka Oct 1, 2025

๐Ÿ”— Copy Links