WordPress Database 101: The Basics
If you watched the first video in this series on a basic website move, you are likely here to learn a bit more about the WordPress database.
We’re going to dig into the WordPress database on a fairly deep level, and it’ll be worth it because you’ll come away with these two key takeaways:
- You’ll be more comfortable in the phpMyAdmin application.
- You’ll understand a bit more about troubleshooting your own site.
Two Steps Before We Get Started
1. Back up your site files
Before making any moves, let’s play it safe and backup your site. (For a refresher on how to do this, go to Step 1 in our post How To Move a WordPress Website to a Different Hosting Server.)
For the most part, you’ll be working on a development site if you’re just learning, so we’re not super worried about breaking anything.
That said, backups are a critical part of being a WordPress developer, so it makes sense to just get in the habit of doing backups early. I almost never touch a website without a backup and, for certain, I would never install or uninstall a plugin or theme without a backup. Get in the habit early and you won’t regret it!
2. Back up your database
As you recall from our previous post, your site’s database holds all your posts, comments, and settings. Access it through your host’s control panel, usually via phpMyAdmin.
Once there:
- Select your database and go to the “Export” tab. I cover a couple of options about this in the video. Pro tip: I use WordPress Developer Resources’ guide every. single. time.
- The only two things you’re going to click each and every time is:
- Add DROP TABLE
- IF NOT EXISTS
In the video below, we also go over ensuring that “save to file” is also checked, but this is covered in the WordPress Developer Resource link above and is almost always checked by default.
About The wp-config.php File
Definitions
This file is found in the root directory (folder) on your server. For a brand new install (not using a website creator/app), this file is called wp-config-sample.php.
This is a great file to use as a guide. There are five (5) key definitions in this file that will make or break your website. If any of them is set incorrectly, your site will not load.
When you create a new database within your hosting environment, these three things are either created for you or you are given the opportunity to select them on your own.
Important notes
- Be sure to record these definitions when you’re creating the database and enter them in the appropriate section. Be careful not to delete the apostrophe marks (‘) when you are pasting these values in.
- Use a standard text editor if you’re going to copy and paste these definitions from the hosting environment as you are creating your database. (Move on why in the next section.)
Possible errors and what they mean
Programs such as Microsoft Word and other word processors will sometimes “encode” the text and use a different kind of apostrophe. If you’re using a text editor that is designed for programming, these incorrect symbols will show an error and the rest of your file will appear to be messed up (see screenshot below).
This just means that the apostrophe at the END of the first section is the wrong one and, therefore, the code reader will not “end” the string where you were hoping.
In the screenshot above, you can see how the user and password have turned RED. This is what my version of VSCode does when there is an error. These programs are super helpful for identifying “fat-finger” errors for you.
The next item is the “DB_HOST.” In most cases, this can remain as the default of “localhost.” In other situations, like SiteGround, they use an IP Address (see next screenshot below). This is one of those scenarios where if everything else is set correctly, you may need to reach out to your host and ask them what that value should be.
The last piece is the table_prefix. This is the value that tells your WordPress install which tables in the database it should use to build the site.
In some cases, you will see multiple prefixes on the table names (see the screenshot below). Simply switching to the correct prefix can fix the issue you are having and render the site correctly.
As you can see in the three examples above, the table_prefix can be just about anything. The default is “wp_” but you may find something totally different in your environment. That’s perfectly fine. As long as it matches what you’ve entered in the wp-config.php file, all will be well.
Wrapping Up
The WordPress database phpMyAdmin interface can be a little scary. And, honestly, it should be. One wrong character in the wrong field can bring your site to its knees. That’s why we always have a backup when doing any sort of work in this area.
Watch the training video > WordPress Database Basics
In case you’re more of a watch-er than a read-er, I put all of the stuff above into the video below!
Featured image credit: Justin Morgan on Unsplash
Want to learn a bit more about working on your WordPress database?
Check out part 3 of our series!
. . .