WordPress – Database Schema

Since WordPress is a dynamic PHP-based application, it requires a database to store all the important data. WordPress uses MySQL to manage database tables and it supports MySQL version 5.6 or greater and MariaDB version 10.1 or greater.

You can have a look at the below image to better understand the tables present in the database of a standard WordPress installation and how they are connected –

WordPress Database Structure
Image: WordPress Database Diagram | Courtesy: WordPress.org

For an even better understanding, you may watch these videos below –

Explore the videos for insights and tutorials on Database Schema in Single and Multisite environments. This section comprises 4 modules with a combined duration of 39 minutes.

Video ContentTime
Single Site Database Overview – prefix, wp_options, wp post, wp_postmeta 11:26
Single Site Database Overview – wp_comments, wp_users, wp_terms08:43
Multisite Database Overview07:46
Deep Dive into User Storage in Multisite Setup10:53

Or you can read more about WordPress Database Schema from the Database Description codex page.

Some things to consider:

  • postmeta, commentmeta, usermeta all act as key-value stores for their respective object types.
    • While it may seem advantageous to directly query term meta, it should be noted that new WP_Query() automatically queries and caches post meta for use with get_post_meta().
  • wp_options is also key-value store, but for the entire site. These are autoloaded and cached in memory by default, unless autoload is set to false using add_option().
  • term_relationships, term_taxonomy, terms, and termmeta work together to provide abstract normalized relationships. Term meta usually has no user interface, except with plugins such as Category and Term Meta Fields, Advanced Custom Fields, or Pods.

References