When you have multiple websites installed on your hosting account, it can be tricky to track which database belongs to which WordPress installation.
Given that most of the unique information belonging to a website lives in the database, you don't want to accidentally edit the wrong one.
To find which WordPress database belongs to your website,
- Check which folder your website is attached to,
- Open wp-config.php from that folder and look for DB_NAME
- Go to wp_options for that database and check that siteurl is your website.
If you already know any of those steps, jump to the next part. Or you can do what I often do and guess the database, open wp_options and check that the website is connected to siteurl or home.
Let's go through those steps in detail.
Check which folder your website is attached to
The first step is to figure out which folder your WordPress files are stored in.
If the website is the main one in the account, this will usually be public_html.
If not, is the website a subdomain (like test.website.com) or an addon domain (like testwebsite.com)?
If the website is a subdomain, go to Subdomains in cPanel. Otherwise, go to Addon Domains.
For this tutorial, we're trying to find the database name for the subdomain test.website.com.
On either the Addon Domains or Subdomains page, look for your domain or subdomain.
Next to it, you'll see which folder its files are in.
In our case, the files are in /public_html/test.
Find the DB_NAME in wp-config.php
To find the WordPress database name, go to the folder where the domain's WordPress files are stored and open wp-config.php by right-clicking and clicking "Edit" or "View".
Look in wp-config.php for the line with DB_NAME. The name of the database for your website is in quotes on that line.
In our example, the line is
define( 'DB_NAME', 'websiteb_test' );
So our database name is websiteb_test.
While you have wp-config.php open, scroll down a bit and notice the value for $table_prefix. Often this will be 'wp_' but in this case it's 'wp4v_'.
This is the prefix in your table. Sometimes, if someone has messed up, you might have different WordPress installations in the same database. They will have different prefixes.
The table prefix in wp-config.php tells your website which prefix your website should use.
Check the website in site_url
The last step is to make sure that the database you think is connected to your website is in fact connected to your website.
In cPanel, go to phpMyAdmin.
Expand the database that you found in wp-config.php.
Go to wp_options. In this example, the prefix set in our wp-config.php file was "wp4v_", so we will go to wp4v_options.
Look for either siteurl or home. They should be the first options in your wp_options table.
Occasionally, one might not be on that first screen. If the website is working properly, there's no need to worry. It's probably later in the table.
You should see your website in siteurl and/or home.
Once you're satisfied that you're working on the correct database, you can proceed with the rest of your work.