There’s no shame in admitting it: I’m a tech dork. It’s one of the main reasons I love working with and writing about WordPress. One aspect about web technology in general that fascinates me is the various database types available, and how each element of the stack connects. A WordPress database is generic in this regard, as it uses industry-typical tech. Still, it’s an area I confess to spending hours tinkering with.
There’s a lot your WordPress database has responsibility for, such as its speed, security, and much more. As such, you want to ensure its smooth running, and that you know how to navigate around it. There are times when it’s necessary to jump into your own database and make changes.
Throughout this post, I want to share my knowledge and experience with you when it comes to managing your WordPress database. Regardless of your skills, I hope you can pick up some new knowledge, or even contribute your own within the post’s comments section!
Why WordPress Needs a Database
Let’s start with the basics. At its core, WordPress is a dynamic Content Management System (CMS) that relies on a database to store and retrieve its information. This database is the backbone of your WordPress site, and holds your posts and pages, user information, site settings, and much more.
Without it, your site can’t provide any dynamic content to the front end. In contrast to a static HTML site, WordPress can generate pages ‘on the fly’ based on the user’s request. This flexibility lets you implement real-time updates, user-specific content, and complex interactions that would be impossible with static files alone.
Practically every piece of functionality WordPress offers uses the database, so it’s a key piece of your tech stack. However, in some cases, that database has more redundancy than you’d expect.
When You Wouldn’t Use a WordPress Database
A WordPress database is a requirement almost all of the time. Even so, there are scenarios where you might opt to bypass this aspect. It may not seem as though this would be viable, but static sites have some traction among certain users.
Our review of the Headless Hostman platform is a good example. It turns your site from dynamic to static. In certain situations and for specific reasons, this can be a boon:
- Simple, content-focused sites. If you don’t update your site much, or require dynamic content, a static site could suit you better.
- Performance-critical applications. Static sites can offer fast loading times since there’s no overheads relating to database queries.
- Enhanced security. Without an exploitable database, static sites can offer greater security against certain types of attacks.
- Lower hosting requirements. You can host static sites on simple file servers. This could be a cost saving with a positive impact.
There are other ways to build static WordPress websites too, such as Jekyll. However, for most WordPress users, driving your site with a database will be the most beneficial approach to take. The dynamic nature of WordPress, in conjunction with its extensive plugin ecosystem, makes it the best choice for most situations.
What the WordPress Database Does
So, knowing that you almost certainly need a database for your WordPress website, what role does it play within your stack? In fact, there are many different roles your WordPress database has. At different times, it has an input into a number of areas:
- Content storage. Every post, page, comment, and media attachment ‘lives’ in the database. This is also true for the associated metadata, any custom post types, and taxonomies.
- User management. The database stores and provides access to the data you associate with user accounts, roles, and permissions.
- Site configuration. The entirety of your WordPress settings sits in the database. This includes theme options and widget configurations for Classic Themes.
All of your themes and plugins store its settings within your WordPress database too. For example, some caching plugins will use the database as a temporary data store for better performance. This often means your database increases in size, thanks to the introduction of additional ‘tables’. I want to tackle this topic next.
WordPress Database Structure: Identifying the Core Database Tables
A database can be complex, but for WordPress, the structural composition is straightforward to explain. The platform builds your database at installation, and populates it with a number of tables.
There’s an equivalence here with a spreadsheet: the document is akin to your database, and each worksheet is like a table.
These database tables relates to specific contexts and purposes. Of course, they also store different types of data. WordPress creates several default tables in your database upon installation, and will be the same for each site:
wp_posts
andwp_postmeta
. The first stores post content, including pages, attachments, and revisions. The second contains the metadata associated with your posts.wp_users
andwp_usermeta
. Stores user account information, and the associated metadata.wp_comments
andwp_commentmeta
. These store data relating to comments and its metadata.wp_terms
andwp_termmeta
. In this instance, ‘terms’ are the categories and tags you define, along with the names of any custom taxonomies.wp_term_taxonomy
: This may seem confusing at first glance. The table describes the taxonomy of each term. For instance, Product Review is a term that associates with a Category taxonomy.wp_term_relationships
: This table maps posts to categories and tags. It’s essential to both the taxonomy system and navigating your site.wp_options
: Consider this one of the most important core tables in your databaseβit stores site-wide settings and options.
WordPress installations also include the wp_links
table. This should store your site’s links as you’d expect. However, it’s a deprecated feature in modern WordPress, so doesn’t see any use unless you run a site that would have used it years ago. Still, I don’t recommend you try to delete or alter it, as aspects of WordPress could depend on it.
Understanding these tables and their relationships is crucial, but that’s not all you have to consider. You can find additional tables too, depending on the themes and plugins you install.
How Plugins and Themes Add Extra Tables to Your Database
A key selling point for WordPress is its extensibility through plugins and themes. Many of these add-ons require additional data storage, and the database is an ideal location for it all. This leads to those themes and plugins to create new database tables upon installation.
For example, a contact form plugin might create a table to store form submissions. An e-commerce plugin could add tables for products, orders, and customer information. Each add-on will have its own needs for creating extra database tables.
In most cases, these are necessary for your third-party themes and plugins to work. However, good development ensures those custom tables disappear upon uninstallation, and this isn’t always the case. A bunch of redundant database tables could impact your site’s performance, so periodically reviewing your database’s structure and removing any orphaned tables is a sound strategy.
How to Access Your WordPress Database
Fortunately, there are a number of ways to get into your WordPress database. I’m not going to go into them all here, because some won’t be suitable.
For instance, while it’s valid to do so, using the command prompt to access your database is going to be a developer-level task. In fact, many developers won’t even do this. They’ll use built-in functionality within editors such as JetBrains’ PhpStorm.
Instead, I’m going to look at some of the most popular and typical ways you would want to use to log into your database: browser tools and third-party apps.
In-Browser Apps
phpMyAdmin and Adminer are arguably the most popular database management tools for WordPress, accessible through the browser. Depending on which host you run with, you’ll often see one or the other within the package.
For example, Kinsta uses phpMyAdmin with its MySQL and MariaDB databases, and Adminer for other types of supported database:
For a host that supports one of these, there’s often a direct link to the tool within the hosting control panel:
Once you log in, there will likely be two databases visible: one will be your site’s database with a unique name. The other will be information_schema
. The intricacies of this database are beyond the scope of the post, but I recommend you keep away from it unless you’re a crack back-end operative!
Once you access your site’s database, you’ll see the tables along with a number of options:
Both Adminer and phpMyAdmin have slightly different interfaces, which means you’ll access similar options in a alternative ways.
Regardless, you’ll find options to browse each table, insert new data, empty the table of its contents, and ‘drop’ the table altogether. This is ‘SQL speak’ for deleting the table, so it’s not an option you’ll want to exercise without some serious thought.
Third-Party Desktop Apps
If you don’t want to use a browser interface to connect to databases, there are a few apps available. I personally use SequelAce, which is an excellent choice for macOS as it’s open-source and functional.
TablePlus is also great, but it’s a premium solutionβand SequelAce does everything TablePlus can do anyway. If you’re a Windows user, you could opt for a tool such as HeidiSQL or MySQL Workbench.
How to Connect to a Database Using SequelAce
Connecting to your database follows a similar method no matter which app you use, although it’s slightly different to using an in-browser app. I’ll show you using SequelAce, but you can transpose this walkthrough to other apps, of course.
To log into your database, you’ll need two sets of credentials:
- Your database connection information.
- Your Secure Shell (SSH) credentials.
Your hosting provider should offer both of these within your control panel. Once you download and install your database app of choice, open it and establish a new connection. This involves entering in both sets of credentials in the right fields:
There are a few common sticking points here that always catch me out. Firstly, the MySQL host will always be 127.0.0.1
, which is a localhost designator. I’ve found that entering a database name and port depends on the host I use.
The biggest SSH headache for me is setting up and validating security keys. I’m getting some tension in my temples just thinking about it! Thankfully, this aspect is beyond the scope of the postβit could be a whole article on its ownβbut is necessary if you want to use SSH and a dedicated database app.
Once you test the connection and log in, the interface feels similar to an in-browser app:
I find the experience better than other solutions, although that’s subjective. I simply think it’s richer, and easier to fulfill some of the regular tasks you have to undertake.
Some of the Common Tasks You’ll Perform With Your WordPress Database
In reality, it will be rare that you have to get in ‘among the weeds’ when it comes to working with your database. Even an Error Establishing Database Connection doesn’t need you to log in.
Many plugins will connect for you, especially for tasks such as backing up your database. Still, this isn’t tough to do manually. You simply open your database, and find the Export option:
This will bring up a dialog box full of options, and will depend on the app you use. SequelAce gives you a few formats to switch between:
With phpMyAdmin, you can choose a Quick export method:
Importing a database is just a simple. In most cases, you can drag-and-drop a suitable database .sql file onto the interface:
Many plugins and hosts will also offer database backups, so double-check the functionality on offer to see whether you get this support.
Optimizing Database Tables
Windows users will understand this next concept. As an exclusive macOS user since 2007, I have not needed to defragment a hard disk in a long time. Your WordPress database can also break into fragments over times, which can lead to slower performance.
Optimizing your database is straightforward in most cases. For instance, Adminer lets you select whichever tables you wish, then will do the necessary once you click Optimize:
It’s similar with phpMyAdmin. You select the tables you wish to optimize, then choose the relevant option from the With selected drop-down menu:
If you’d prefer to use a plugin, WP-Optimize could be suitable:
This doesn’t only help you optimize your database, but can carry out the task with just as much simplicity as the manual method.
Changing Content Through the Database
Because the WordPress database contains all of your site’s data and settings, you actually have full scope to edit it within the database. This isn’t a typical way you’ll edit any of these, because of a few reasons:
- The database interface is not a content editor.
- You need to set string encoding and certain security formatting algorithms for some content (such as passwords).
- You could expose your site to vulnerabilities if you get the process wrong.
However, editing through the database will have some specific use cases that center around not being able to log into your site. For instance, my son has a website that I helped him build as a mini-project. The idea was to teach him about WordPress and about the industry I work in.
As with my other sites, I used SpinupWP and DigitalOcean as the hosting stack. The site installation was fine, but the single primary Administrator wasn’t able to log in. Given this, I needed to go into the database and tinker with the user credentials:
This was a last resort that didn’t work in the end eitherβthe actual cause was a corrupted user profile (I think) that needed regeneration. Changing passwords through the database can do more harm than good, so I’d advise against it unless you have the best reason to do so.
In other cases, you may want to deactivate plugins or themes, as you can with SFTP. This is something you’ll find within the wp_options
table:
Here, look for the active_plugins
entry, and change the value to a:0:{}
. This will disable all of your site’s plugins. It’s one way to troubleshoot an error such as the White Screen of Death (WSoD).
Your WordPress Database Doesn’t Have to Be Scary
Managing your WordPress database might seem daunting at first, but learning how to do this is an essential site skill that can help in a number of ways. In fact, like being a crack martial artist, you may not ever need to utilize that knowledge, what with the proliferation of WordPress plugins and tools that handle many of the associated tasks. Still, in some cases, accessing the database will be necessary, and I hope to have given you enough skill to save the day.
Do you have any questions about accessing, using, or managing your WordPress database? Maybe you have a tip to share that helps your own database management? I’d love to hear all of your thoughts in the comments section below!