The WordPress Database
WordPress keeps your posts, pages, settings, and users in a MySQL database. Knowing where its credentials live and how to work with a few key tables lets you recover from lockouts and fix common problems.
Finding Your Credentials
WordPress stores its database connection details in the wp-config.php file in the root of your site. Open it with cPanel File Manager or FTP and look for these four lines:
define( 'DB_NAME', 'cpuser_wp' );
define( 'DB_USER', 'cpuser_wpuser' );
define( 'DB_PASSWORD', 'your-password-here' );
define( 'DB_HOST', 'localhost' );
- DB_NAME — the database WordPress uses, with the account-name prefix.
- DB_USER — the database user, also prefixed.
- DB_PASSWORD — that user's password.
- DB_HOST — always
localhoston our servers.
The Table Prefix
Just below the credentials you will find the table prefix:
$table_prefix = 'wp_';
By default WordPress tables begin with wp_ — for example wp_posts, wp_options, and wp_users. Some installs use a custom prefix for security, so always check this value before running SQL against the tables. In the examples below, substitute your actual prefix if it is not wp_.
Changing the Database Password
If you rotate the database user's password, you must update it in two places or WordPress will lose its connection:
- In cPanel, open MySQL Databases, find the user under Current Users, and click Change Password. Set a new strong password.
- Edit
wp-config.phpand update theDB_PASSWORDline to match exactly. - Save the file and reload your site to confirm it connects.
wp-config.php produces the Error establishing a database connection message. Make sure both values are identical.
Common Tasks in phpMyAdmin
Open phpMyAdmin from cPanel and select your WordPress database before running any of the following.
Reset an Administrator Password
If you are locked out and cannot use the email reset, set a new password directly. Run this in the SQL tab, replacing the values as needed:
UPDATE wp_users SET user_pass = MD5('NewPassword123') WHERE user_login = 'admin';
WordPress accepts the MD5 hash and upgrades it to a stronger hash the next time you log in.
Fix the Site URL
If your site redirects to the wrong domain after a move, correct the siteurl and home values in wp_options:
UPDATE wp_options SET option_value = 'https://example.com' WHERE option_name IN ('siteurl', 'home');
The Built-in Repair Tool
WordPress ships with a repair page that can fix a corrupted database without any SQL. It is disabled by default. To turn it on, add this line to wp-config.php, above the line that reads /* That's all, stop editing! */:
define('WP_ALLOW_REPAIR', true);
Then visit /wp-admin/maint/repair.php on your site and click Repair Database (or Repair and Optimize).
WP_ALLOW_REPAIR is enabled, so anyone who finds the URL can run it. Remove the line from wp-config.php as soon as you are done.