How to Find Which Database Your WordPress Site Uses (and Its Username and Password)

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_';
SettingWhat it isWhat it should look like on our servers
DB_NAMEThe database the site uses.Your cPanel username, an underscore, then a name, e.g. username_wp482.
DB_USERThe database user WordPress logs in as.Also starts with username_.
DB_PASSWORDThat database user's password.Any text. It's not your cPanel, email or WordPress admin password.
DB_HOSTWhere the database server is.localhost -- the database runs on the same server as your site.
$table_prefixThe 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 in public_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.php and 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.php next to wp-admin and wp-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

  1. Log in to cPanel (from the client area: Services > My Services, choose your plan, then Log in to cPanel).
  2. Go to Files > File Manager and open the folder from Step 1.
  3. Right-click wp-config.php and choose View. Viewing is read-only, so you can't change anything by accident.
  4. Note the values between the second pair of quote marks on the DB_NAME, DB_USER and DB_HOST lines, and the $table_prefix value.
  5. Only copy the DB_PASSWORD value if you actually need it (for example to connect a desktop app). Don't paste it into email or chat.
  6. 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

  1. Go to Databases > Manage My Databases.
  2. In Current Databases, find the name that exactly matches DB_NAME.
  3. In the same row, the Privileged Users column should list the DB_USER value. That confirms the user is allowed to use the database.
  4. 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:

  1. Go to Databases > phpMyAdmin and click the database in the left panel.
  2. The table names should start with your $table_prefix, for example wp_options.
  3. Open the options table (for example wp_options) and look at the siteurl row. 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.php on the account, write down the folder, the site address, DB_NAME, DB_USER and the prefix.
  • Databases that appear in no wp-config.php aren'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:

  1. In Manage My Databases > Current Users, click Change Password next to the DB_USER. Use Password Generator, copy the password and save it.
  2. Immediately open wp-config.php in File Manager with Edit, replace only the text between the quote marks on the DB_PASSWORD line, and click Save Changes.
  3. 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.old or wp-config.txt aren'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 outside public_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 from https://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

Still stuck? Open a support ticket and the Instant Access Internet Services team will help.

Ultrafast LiteSpeed hosting from InstantAccess.net: free SSL, free backups, cPanel included, no contracts. Check out our $10/month hosting.
  • which database does wordpress use, find wordpress database name, wordpress database username and password, wp-config.php database settings, find db_name wp-config, wordpress table prefix, where is wp-config.php
  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

How to Change a MySQL Database User's Password

You might need to change a database password after a security scare, when a developer leaves, or...

How to Create a MySQL Database and User in cPanel

Most website software, including WordPress, Joomla and online shops, stores its content in a...

How to Import and Export a Database with phpMyAdmin

phpMyAdmin lets you save a copy of a database to your computer or load a database from a file,...

How to Open phpMyAdmin from cPanel and Find Your Way Around

phpMyAdmin is a web page for looking inside your MySQL databases: you can see the tables your...

How to Move a MySQL Database from Another Host to Your Account

Moving a website to us usually means moving two things: the files and the MySQL database behind...