Home Blog WordPress Management The ultimate guide to the WordPress database

The ultimate guide Wordpress database

The ultimate guide to the WordPress database

At its core, WordPress is a CMS (Content Management System). To manage content, it needs to be able to store it. WordPress does this through folders and files, and a database. We have previously covered the WordPress filesystem in a separate article; we will focus on the database this time around.

In this article, we will be looking at the WordPress database, its structure, and how each field works. We have also included a brief history lesson on MySQL. Hint – The My in MySQL does not mean it’s yours; My is an actual person, but who? – Continue reading to find out.

A (very) brief history of SQL, MySQL, and MariaDB

WordPress uses an RDBMS called MySQL. Technically it’s MySQL-based since, increasingly, MariaDB is being used instead of MySQL. SQL stands for Structured Query Language and is the language we use to interact with the database – and not the database itself.

MySQL has played a significant role in the growth of the internet as we know it today. First introduced in 1995 as an alternative to products offered by Microsoft and Oracle, it quickly became the golden RDBMS standard of choice.

MySQL’s history is colorful, having been acquired by Sun Microsystems and then Oracle (Oracle acquired Sun Microsystems and MySQL with it).

In response to the acquisition of MySQL by Oracle, Monty Widenius, the original creator of MySQL, forked MySQL into MariaDB, which he named after his daughter, Maria. (Interestingly, MySQL is named after Monty’s other daughter – My). Over time, differences between MariaDB and MySQL developed; however, the two remain interchangeable in many scenarios, including WordPress databases.

In fact, in many cases, MariaDB is considered to be a drop-in replacement to MySQL. This means that you can uninstall MySQL, install MariaDB instead, and continue working as if nothing changed. Having said that, MariaDB can offer performance improvements in some situations and also offers wider compatibility with, for example, storage engines.

It’s important to note that MySQL remains free and is released under a dual-license system. In many cases, MySQL is used to refer to databases that are either MySQL or MariaDB.

How to access the WordPress database

There are a few different options available when it comes to connecting to the WordPress database. The method or methods available to you will largely depend on the type of WordPress hosting that you use. If you’re not sure how your server is configured, speak with your hosting provider or systems administrator. Either way, options can include;

phpMyAdmin

phpMyAdmin is a favorite tool as it allows us to connect to the database via a web-based GUI. phpMyAdmin needs to be installed on the same server that hosts the database, with many hosting providers offering phpMyAdmin straight out of the box.

Plesk/cPanel

Plesk and cPanel are two control panel platforms that serve a similar function – a user interface that facilitates server management. Of course, there are certain key differences, including the technologies and Operating Systems they support. Either way, they also allow us to access databases, albeit in slightly different ways.

SSH/MySQL/mariaDB client

SSH is a less user-friendly way to connect to a database, offering a CLI (Command Line Interface) instead of a GUI. Because of this, a deeper understanding of SQL commands is recommended. SSH needs to be explicitly set up on the same server that hosts the database before connecting to it.

Plugins

You can also use WordPress plugins to access your WordPress database. Using a plugin, you can access the database straight from your WordPress admin console. Here, you’ll need to make sure that you choose a plugin from a reputable supplier and follow all applicable best practices to keep your data safe. If you are not sure which plugin to go for, read our guide on how to choose the best plugins for your WordPress website.

WordPress database structure

The WordPress database is made up of 12 tables. Each table, by default, starts with the wp_ prefix; however, this can be changed during the initial installation and configuration process. Changing the prefix is generally recommended for WordPress security reasons, especially if you intend or already have multiple installations on the same server.

The 12 tables that make up the WordPress database are as follows (listed in alphabetical order):

We will now go through each table individually and look at what data it stores and its internal structure.

Table structure

Before we get into the details of each table, it is worth taking some time to look at how it is structured. If you’re not familiar with database documentation, this section will give you a crash course that you’ll find helpful in the next section. On the other hand, if you’re pretty familiar with SQL tables, feel free to skip forward.

  • Field name – This is the name of the field, which you’ll find in the SQL table
  • Description – We have put this in to help you understand what kind of data the field holds
  • Type – This is the datatype that the field accepts. Numbers in brackets represent the hard limit on the number of acceptable characters we can enter
  • Null – it is not clear why this field is used at the moment
  • Key – This tells us if the entry is a key or not. There are different types of keys, including:
    • Primary
    • Primary (Part)
    • Index
    • Index (Part)
    • Unique
    • Multiple
  • Default – If the entry has a default value, the default value will be listed here
  • Notes – Any additional notes

wp_commentmeta

The wp_commentsmeta table stores metadata related to comments. Comments are stored separately in the wp_comments table. The table has the following fields:

Column nameDescriptionTypeNullKeyDefault
meta_idThis is a unique ID for the entry. It increments automaticallybigint(20)unsignedPrimary
comment_idThis is the ID of the comment the metadata relates to as found in the wp_comments tablebigint(20)unsignedIndex0
meta_keyThis identifies the type of metadata the entry is forvarchar(255)YesIndexNull
meta_valueThis is the actual metadatalongtextYesNull

wp_comments

The wp_comments table stores post comments. Metadata related to comments is stored in the wp_commentmeta table. The table has the following columns:

Column nameDescriptionTypeNullKeyDefault
comment_IDThis is a unique ID for the entry. It increments automaticallybigint(20)PrimaryNA
comment_post_IDThis is the ID of the post the comment was written for, as found in the wp_posts tablebigint(20)Index0
comment_authorThis is the name of the author who wrote the commenttinytext
comment_author_emailThis is the email address of the author who wrote the commentvarchar(100)Index
comment_author_urlThis is the website URL of the author who wrote the commentvarchar(200)
comment_author_IPThis is the IP address of the author who wrote the commentvarchar(100)
comment_dateThis is the date and time on which the comment was posteddatetime0000-00-00 00:00:00
comment_date_gmtThis is the GMT (Greenwich Meridian Time) date and time on which the comment was posteddatetimeIndex and Index Pt20000-00-00 00:00:00
comment_contentThis is the actual comment lefttext
comment_karmaThis is available for use by plugins for comment management purposesint(11)
comment_approvedThis indicates whether the comment has been approved or notvarchar(20)Index Part 10
comment_agentThis is where the comment was posted fromvarchar(255)
comment_typeThis is the type of comment leftvarchar(20)
comment_parentIf the comment is a reply, this field indicates parent commentbigint(20)unsignedIndex0
user_idIf a commenting user is registered, this will be their ID as available in wp_usersbigint(20)unsigned0

This table was originally created to support blogrolls, a feature that was dropped starting with WordPress 3.5. It is kept for backward compatibility but is no longer in use. The table has the following columns:

Column nameDescriptionTypeNullKeyDefault
link_idThis is a unique ID for the entry. Increments automaticallybigint (20) unsignedPrimary
link_urlThis is the URL of the linkvarchar(255)
link_name
This is the name of the linkvarchar(255)
link_imageThis is the URL of the link-related imagevarchar(255)
link_targetThis is the link’s target framevarchar(25)
link_desciptionThis is a description of the linkvarchar(255)
link_visibleThis tells us if the link is publicly shown or notvarchar(20)IndexY
link_ownerThis is the user ID of the user who created the link as available in wp_usersbigint (20) unsigned1
link_ratingThis is the rating of the linkint(11)0
link_updatedThis is the date and time the link was updateddatetime0000-00-00 00:00:00
link_relThis is the relationship of the linkvarchar(255)
link_notesThis is notes about the linkmediumtext
link_rssThis is the rss feed address of the linkvarchar(255)

wp_options

WordPress File Changes Monitor scan frequency

WordPress settings configured through the admin console are stored here. Plugins and themes will typically also store settings information here, as illustrated in the screenshot below. Here we can see our very own Website File Changes Monitor’s scan frequency option set to daily.

The table has the following columns:

Column nameDescriptionTypeNullKeyDefault
option_idThis is a unique ID for the entry. Increments automatically.bigint(20) unsignedPrimary
option_nameThis is the name of the option/settingvarchar(64)Unique
option_valueThis is the value of the setting being storedlongtext
autoloadThis setting tells wp_load_alloptions() if it should autoload the option or notvarchar(20)Indexyes

wp_postmeta

Posts metadata that accompanies each post is stored here. Metadata can include attached files, thumbnails, desired post slug, and other such information. The table has the following columns:

Column nameDescriptionTypeNullKeyDefault
meta_idThis is a unique ID for the entry. Increments automaticallybigint(20) unsignedPrimary
Field name
post_id

This is the ID of the post the metadata is associated with as available in wp_postsbigint(20) unsignedIndex0
meta_keyThis is an index key that identifies the metadata, since each post can have more than one metadatavarchar(255)YesIndexNull
meta_valueThis is the actual metadatalongtextYesNull

wp_posts

Sample page included in every WordPress fresh installation

The wp_posts table is a major one and contains the core of WordPress data. It holds the actual posts, pages, as well as navigation menu items, as seen in the below example showing the default sample page included in every WordPress fresh installation.

The table has the following columns:

Column nameDescriptionTypeNullKeyDefault
IDThis is a unique ID for the entry. Increments automaticallybigint(20) unsignedPrimary and Index (Part 4)
post_authorThis is the ID of the author who wrote the post as available in wp_usersbigint(20) unsignedIndex0
post_dateThis is the date and time when the post was createddatetimeIndex (Part 3)0000-00-00 00:00:00
post_date_gmtThis is the GMT (Greenwich Mean Time) date and time when the post was createddatetime0000-00-00 00:00:00
post_contentThis is the actual content of the postlongtext
post_titleThis is the title of the posttext
post_excerptThis is an excerpt of the posttext
post_statusThis is the status of the postvarchar(20)Index (Part 2)publish
comment_statusThis tells us if comments on the post are allowed or notvarchar(20)open
ping_statusThis tells us if ping and trackbacks are allowed or notvarchar(20)open
post_passwordPosts can be password-protected with any applicable password stored herevarchar(20)
post_nameThis is the post title’s URL slug varchar(200)index
to_pingThis is a list of URLs that WordPress should send pingbacks to whenever the post is updatedtext
pingedThis is a list of URLs that WordPress has pingbacked when updatedtext
post_modifiedThis is the date and time of the post’s last modificationdatetime0000-00-00 00:00:00
post_modified_gmtThis is the GMT date and time of the post’s last modificationdatetime0000-00-00 00:00:00
post_content_filteredThis is a filtered version of post_content that’s typically used by plugins for caching purposeslongtext
post_parentWhen post is a revision or attachment, this creates the parent-child relationshipbigint(20) unsignedIndex0
guidThis is the Global Unique Identifier (GUID) of the postvarchar(255)
menu_orderThis is the order number in which pages and non-post items appearint(11)0
post_typeThis identifies the content typevarchar(20)Index (Part 1)post
post_mime_typeThis is the mime type of post attachmentsvarchar(100)
comment_countThis is the total number of comments, trackbacks, and pingbacksbigint(20)0

wp_terms

Terms are classification objects used to classify objects in WordPress. For example, categories and tags used in posts are types of terms. This table contains all the different types of terms used throughout WordPress. The table has the following columns:

Column nameDescriptionTypeNullKeyDefault
term_idThis is a unique ID for the entry. Increments automaticallybigint(20) unsignedPrimary
nameThis is the name of the termvarchar(200)Index
slugThis is the slug of the termvarchar(200)Multiple
term_groupThis is an alias that themes and plugins can use to group terms tigetherbigint(10)0

wp_termmeta

This table stores the metadata associated with terms found in wp_terms. The table has the following columns:

Column nameDescriptionTypeNullKeyDefault
meta_idThis is a unique ID for the entry. Increments automaticallybigint(20) unsignedPrimary
term_idThis is the ID of the term the metadata relates to as available in wp_termsbigint(20) unsignedIndex0
meta_keyThis is an identifier key for the term metadatavarchar(255)YesIndexNULL
meta_valueThis is the actual metadatalongtextYesNULL

wp_term_relationships

This table maintains relationships between posts and taxonomies. The table has the following columns:

Column nameDescriptionTypeNullKeyDefault
object_idThis is the ID of the post as available in wp_postsbigint(20) unsignedPrimary (Part 1)0
term_taxonomy_idThis is the ID of the term taxonomy as available in wp_term_taxonomybigint(20) unsignedPrimary (Part 2) and Index0
term_orderThis is the order of the termint(11)0

wp_term_taxonomy

This table gives terms taxonomies and, as such, a context in which they can be used. For example, we can use the term database as a post category and as a product category (assuming we are selling database services). In this case, post category and product category are term taxonomies. The table has the following columns:

Column nameDescriptionTypeNullKeyDefault
term_taxonomy_idThis is a unique ID for the entry. Increments automaticallybigint(20) unsignedPrimary
term_idThis is the ID of the term as available in wp_termsbigint(20) unsignedUnique (Part 1)0
taxonomyThis is the slug of the taxonomyvarchar(32)Unique (Part 2) and Index
descriptionThis is a description of the taxonomylongtext
parentThis is the ID of the parent taxonomy if taxonomy is a childbigint(20) unsigned0
countThis is the number of objects that are assigned this taxonomybigint(20)0

wp_usermeta

This table stores additional user data that is not found in the wp_users table. WordPress itself, as well as plugins or themes, can make use of this table.

An example of user metadata is the user nickname. Although WordPress includes this field by default, it is still part of the metadata, as shown below. Another example is WooCommerce; an ecommerce plugin that uses this table to store customer information such as shipping address.

User nickname metadata

The table has the following columns:

Column nameDescriptionTypeNullKeyDefault
umeta_idThis is a unique ID for the entry. Increments automaticallybigint(20) unsignedPrimary
user_idThis is the user’s ID the information relates to as found in wp_usersbigint(20) unsignedIndex0
meta_keyThis is a key identifier for the meta entryvarchar(255)yesIndexNull
meta_valueThis is the actual metadatalongtextYesNull

wp_users

WordPress users’ information is stored here. With users being an integral part of the WordPress ecosystem, this table is an essential one.

The table only stores the core information for each user, as shown in the example below. All other information is stored in the wp_usermeta table.

WordPress users other meta information

The table has the following columns:

Column nameDescriptionTypeNullKeyDefault
IDThis is a unique ID for the entry. Increments automaticallybigint(20) unsignedPrimary
user_loginThis is the user’s usernamevarchar(60)Index
user_passThis is the user’s passwordvarchar(64)
user_nicenameThis is the user’s display namevarchar(50)Index
user_emailThis is the user’s email addressvarchar(100)
user_urlThis is the user’s URL (ex. website)varchar(100)
user_registeredThis is the date and time on which the user was registereddatetime0000-00-00 00:00:00
user_activation_keyThis is the user’s activation key, used for resetting their passwordvarchar(60)
user_statusThis is no longer used as from WordPress 3.0, but used to indicate if the user was spamint(11)0
display_nameThis is the user’s public display namevarchar(250)

Get familiar with the WordPress database

Databases can be quite intimidating to the uninitiated – after all, they hold all the data required for WordPress to work. While it is true that a misstep here can bring the site crashing down, do not let this intimidate you. After all, knowing your way around the WordPress database can greatly ease your troubleshooting efforts should this be required.

Setting up a testing or staging environment can provide you with a safe space in which you are free to experiment without risking taking your website offline. You can even set up a XAMPP staging environment on your computer for free – providing you with everything you need to master WordPress’ database.

Posted inWordPress Management
Joel Farrugia
Joel Barbara

Joel is our technical writer responsible for writing the different kinds of content we need. With a background in tech and content, he has a passion for making technology accessible and understandable for everyone. You can reach Joel at joel@melapress.com.


2 thoughts on “The ultimate guide to the WordPress database

  1. as wordpress evolved from blog to CMS hasn’t _postmeta become the WordPress junk drawer? it just gets filled up to ridiculous levels with every random thing and becomes unwieldy.

    1. Hello Stan,

      Thanks for reaching out.

      Indeed, it seems that the _postmeta table has become that. Well let’s see how things evolve with WordPress. We are seeing a lot of big changes with every version upgrade.

      Best,
      Rado


Leave a Reply

Your email address will not be published. Required fields are marked *

Stay in the loop

Subscribe to the Melapress newsletter and receive curated WordPress management and security tips and content.

Newsletter icon

It’s free and you can unsubscribe whenever you want. Check our blog for a taste.

Envelope icon
newsletter-pop-up