Before you can restore, move, repair or clean up a WordPress database, you need to know which one it is -- and on an account with a few sites or an old test install, that isn't always obvious. This guide shows how to find which database your WordPress site uses, along with its username and password, by reading wp-config.php in File Manager and matching it up in cPanel. It also covers sites with several databases and how to keep those details safe.
Where WordPress keeps its database details
Every WordPress site has a file called wp-config.php in its main folder. Near the top are four lines that tell WordPress how to reach its database:
define( 'DB_NAME', 'username_wp482' );
define( 'DB_USER', 'username_wp482u' );
define( 'DB_PASSWORD', 'k7Fq2mZp9XwL4vRt' );
define( 'DB_HOST', 'localhost' );
Further down there's one more line that matters:
$table_prefix = 'wp_';
| Setting | What it is | What it should look like on our servers |
|---|---|---|
DB_NAME | The database the site uses. | Your cPanel username, an underscore, then a name, e.g. username_wp482. |
DB_USER | The database user WordPress logs in as. | Also starts with username_. |
DB_PASSWORD | That database user's password. | Any text. It's not your cPanel, email or WordPress admin password. |
DB_HOST | Where the database server is. | localhost -- the database runs on the same server as your site. |
$table_prefix | The start of every table name for this site. | Often wp_, but WP Toolkit and security plugins often use something random like wpx7_. |
The table prefix is how two WordPress sites can share one database without mixing up their content: one site's tables are wp_posts, wp_options and so on, the other's are blog2_posts, blog2_options.
Step 1: Find the right wp-config.php
If you have one WordPress site on your main domain, the file is in public_html. It can also be somewhere else:
- In a subfolder, if the site lives at an address like
example.com/blog-- look inpublic_html/blog. - In a subdomain's folder, if the site is at
shop.example.com. The folder is shown as the Document Root in Domains > Domains. - In a staging folder created by WP Toolkit. Staging sites have their own
wp-config.phpand their own database. - One level above the WordPress folder. WordPress also looks in the parent folder, and some security guides suggest moving it there. If there's no
wp-config.phpnext towp-adminandwp-content, check the folder above.
Not sure where a site lives? Go to Domains > WordPress Management (WP Toolkit). Each site card shows its address, and the site's details show the folder it's installed in.
Step 2: Read the database details
- Log in to cPanel (from the client area: Services > My Services, choose your plan, then Log in to cPanel).
- Go to Files > File Manager and open the folder from Step 1.
- Right-click
wp-config.phpand choose View. Viewing is read-only, so you can't change anything by accident. - Note the values between the second pair of quote marks on the
DB_NAME,DB_USERandDB_HOSTlines, and the$table_prefixvalue. - Only copy the
DB_PASSWORDvalue if you actually need it (for example to connect a desktop app). Don't paste it into email or chat. - Close the viewer.
The command-line way
If you're comfortable with SSH, open Advanced > Terminal and let WP-CLI read the file for you:
cd ~/public_html
wp config get DB_NAME
wp config get DB_USER
wp config get DB_HOST
wp config get table_prefix
To list every WordPress install on the account together with the database it uses:
grep -H "DB_NAME" ~/public_html/wp-config.php ~/public_html/*/wp-config.php ~/*/wp-config.php 2>/dev/null
Each line of output shows a file and the database named in it.
Step 3: Match it up in cPanel
- Go to Databases > Manage My Databases.
- In Current Databases, find the name that exactly matches
DB_NAME. - In the same row, the Privileged Users column should list the
DB_USERvalue. That confirms the user is allowed to use the database. - Optional: the Size column shows how big the database is, which helps if you're deciding what to back up or clean up.
Then check the tables really belong to this site:
- Go to Databases > phpMyAdmin and click the database in the left panel.
- The table names should start with your
$table_prefix, for examplewp_options. - Open the
optionstable (for examplewp_options) and look at thesiteurlrow. It should show the site's address.
If siteurl shows a different address, you've found another site's tables. That's common with old copies and tests.
Accounts with several sites or databases
It's easy to end up with more databases than sites: a staging copy, a test install, a failed migration, a site you replaced. A few tips for keeping track:
- Make a quick list. For each
wp-config.phpon the account, write down the folder, the site address,DB_NAME,DB_USERand the prefix. - Databases that appear in no
wp-config.phparen't used by any WordPress site. They may belong to other software, or be leftovers. Check before removing anything -- see our guide on deleting databases safely. - One database, several prefixes. If phpMyAdmin shows tables with two different prefixes in the same database, two sites share it. Never drop tables with a prefix you haven't matched to a site.
- Staging sites use their own database. Push changes and remove staging sites through WP Toolkit, not by deleting their databases by hand.
Changing the database password safely
cPanel can't show you a database user's password -- the only copy you can read is the one in wp-config.php. If you need a new one (a developer has left, you think it leaked, or you simply want to rotate it), you must change it in both places, one straight after the other:
- In Manage My Databases > Current Users, click Change Password next to the
DB_USER. Use Password Generator, copy the password and save it. - Immediately open
wp-config.phpin File Manager with Edit, replace only the text between the quote marks on theDB_PASSWORDline, and click Save Changes. - Load the site. If you see "Error establishing a database connection", the two passwords don't match -- check for extra spaces or a missing quote mark.
Between steps 1 and 2 the site can't reach its database, so have both windows ready. Our password guide in the related links covers this in more detail. If the user is shared by more than one site, update every wp-config.php that uses it.
Keep wp-config.php private
wp-config.php holds the keys to your whole site: anyone with the database password can read customer details, create an admin account, or wipe your content. Treat it like a password.
- Never share the file itself -- not by email, not in a forum post, not in a screenshot. If someone asks for "your wp-config", send only the settings they actually need, and blank out the password and the security keys.
- Don't leave copies in your website folder. Files like
wp-config.php.bak,wp-config.oldorwp-config.txtaren't run as PHP, so a visitor who guesses the name can download them as plain text with your password inside. Delete them, or move them outsidepublic_html. - Keep it out of Git repositories and public code sharing sites.
- Support will never email you asking for it. If we need database access to help you, we'll ask in a support ticket in the client area -- never follow links in an email that claims to be about your account.
- If it may have leaked, change the database password (above), change your WordPress admin passwords, and replace the security keys and salts further down in
wp-config.php(you can get a fresh set fromhttps://api.wordpress.org/secret-key/1.1/salt/). Changing the salts logs everyone out, which is what you want.
Troubleshooting
There's no wp-config.php in public_html
Check whether File Manager shows hidden files (it doesn't hide wp-config.php, but you may be in the wrong folder), look one folder up, and check WP Toolkit for the site's install path. If the site loads but you can't find the file, open a ticket.
The DB_NAME doesn't exist in cPanel
The site was probably copied from another host and the file still has the old names -- in that case the site is showing a database error too. See the database connection guide in the related links.
The lines look different
Some hosts and tools write them as define('DB_NAME', 'x'); without spaces, or use double quotes. That's fine. If a value is read from somewhere else, such as getenv('DB_NAME'), a developer has set up the site differently -- ask them, or open a ticket.
DB_HOST isn't localhost
On our servers it should be localhost. A leftover host name from another provider will stop the site connecting. Change it to localhost and save.
Common questions
Is the database password the same as my WordPress admin password?
No. The database password is only used by WordPress itself. You log in to the dashboard with your WordPress username and password, which are stored separately.
Do I need the database password to use phpMyAdmin?
No. Open phpMyAdmin from cPanel and it logs you in automatically.
Can I rename the database to something clearer?
You can, with Rename in Manage My Databases, but you must then update DB_NAME in wp-config.php. Take a backup first. For most people it's easier to keep the name and note it down.
Related guides
- How to Change a MySQL Database User's Password
- How to Fix "Error Establishing a Database Connection" in WordPress
- How to Create a MySQL Database and User in cPanel
- How to Edit a File in cPanel File Manager
- What to Do If Your WordPress Site Is Hacked
- Never Click Links in Emails About Your Account -- Log In Directly Instead
Still stuck? Open a support ticket and the Instant Access Internet Services team will help.
