Plugins Plugin hub Backup SEO Caching Security Forms WooCommerce Images Best backup plugins
Hosting Hosting directory Shared hosting Managed WordPress Cloud hosting VPS hosting By reader location Hosting finder
Themes & builders Compare Rank Math vs Yoast
Tools All tools Hosting finder Plugin stack builder Cost calculator Salt generator Theme detector Who is hosting this? Speed test Headline analyzer robots.txt generator Redirect generator Uptime calculator Blog name generator
Blog Best backup plugins Deals
Guides All guides Speed up WordPress Choose hosting Back up WordPress
How we test

Security · Guide

How to Change WordPress Database Password (Step by Step)

How to Change WordPress Database Password (Step by Step)

Short answer

Change the MySQL user's password in your hosting panel, phpMyAdmin or with an ALTER USER query. Then edit the DB_PASSWORD line in wp-config so it matches exactly, save the file and test your site and dashboard.

Key takeaways

  • The password must match on the server and in wp-config.php.
  • Use cPanel MySQL Databases on most shared hosts.
  • ALTER USER works when you have database admin rights.
  • Avoid quotes and backslashes in the new password.
  • Rotate security keys after a breach to log everyone out.

How do you change the WordPress database password?

Change the MySQL user's password in your hosting panel or phpMyAdmin, then immediately update the DB_PASSWORD line in wp-config.php to the same new value so WordPress can still connect.

WordPress stores its content in a MySQL or MariaDB database. It connects with a database username and password saved in the wp-config.php file.

Those two places must always match. If you change the password in one place only, your site shows Error establishing a database connection until you fix the other.

This guide is about the database password. If you want to change a user's login password for the dashboard, see how to change a WordPress password instead.

Why would you change the database password?

Change the database password after a hack or suspected leak, when a developer or agency no longer needs access, if the password was weak, or as part of regular security housekeeping.

Common reasons include:

  • Your site was compromised, and attackers may have read wp-config.php.
  • A former developer, freelancer or host had access to your files.
  • The password was auto-generated years ago or reused elsewhere.
  • Your security policy requires periodic credential changes.

After a hack, changing the database password is one of several steps. Our guide on what to do after a WordPress hack lists the rest.

What do you need before you start?

You need access to your hosting control panel or database tool, file access to edit wp-config.php, the database username, and a fresh backup of your files and database.

Prepare these first:

  1. A backup. Follow our guide on how to back up a WordPress database.
  2. Database details. Open wp-config.php and note DB_NAME, DB_USER and DB_HOST. See how to find your WordPress database name.
  3. File access. Use your host's file manager, SFTP or SSH.
  4. A strong new password. Generate a long random password with a password manager.

Avoid quotes, backslashes and dollar signs in the new password. They can break the PHP string in wp-config.php unless escaped correctly.

How do you change the password in cPanel?

In cPanel, open MySQL Databases, scroll to Current Users, click Change Password next to the WordPress database user, enter the new password, and save it.

Steps:

  1. Log in to cPanel.
  2. Open MySQL Databases under the Databases section.
  3. Scroll to Current Users.
  4. Find the user that matches DB_USER in wp-config.php.
  5. Click Change Password.
  6. Enter or generate a new password and copy it somewhere safe.
  7. Click Change Password to save.

The cPanel MySQL Databases documentation explains this screen in more detail.

Your site will show a database connection error from this moment until you update wp-config.php. Move straight to that step.

To keep downtime short, open wp-config.php in a second browser tab before you change the password. Then you can paste the new value the moment the server change is saved.

On busy sites, consider turning on a maintenance page first. Visitors then see a friendly notice instead of a raw database error for the minute or two the switch takes.

How do you change it on other hosts?

Most hosts have a databases section in their own dashboard where you select the WordPress database user and choose a reset or change password option.

Managed WordPress hosts and custom panels name things differently. Look for Databases, MySQL, or Site Tools > MySQL.

Some managed hosts generate database credentials automatically and update wp-config.php for you. Others do not allow direct changes and handle it through support.

If you cannot find the option, search your host's knowledge base for change MySQL user password or ask their support team.

How do you change it with SQL?

If you have database admin rights, run an ALTER USER statement for the WordPress database user in phpMyAdmin or the MySQL command line, then update wp-config.php.

The SQL looks like this:

ALTER USER 'wp_user'@'localhost' IDENTIFIED BY 'new-strong-password';

Replace wp_user with your DB_USER value and localhost with the host the user connects from. The MySQL ALTER USER reference explains the full syntax.

On shared hosting, your account usually lacks permission to run this. Use the control panel method there.

In phpMyAdmin, you may also see a User accounts tab with an Edit privileges and Change password option. This tab only appears when your login has the needed rights.

How do you update wp-config.php?

Open wp-config.php in the site's root folder, replace the value inside the DB_PASSWORD quotes with the new password, save the file, and reload your site.

Find this line:

define( 'DB_PASSWORD', 'old-password-here' );

Change it to:

define( 'DB_PASSWORD', 'new-strong-password' );

Keep the single quotes and the semicolon. Do not add spaces inside the quotes.

The file usually sits in the same folder as wp-admin and wp-content. If you cannot find it, read where to find wp-config.php. The wp-config.php documentation describes every database constant.

What changes where?

The password lives in two places, the database server and wp-config.php, and every other setting stays the same unless you also rename the user or database.

SettingWhere it livesChange it?
Database passwordDatabase server and DB_PASSWORDYes, in both places
Database userDatabase server and DB_USEROnly if you create a new user
Database nameDatabase server and DB_NAMENo
Database hostDB_HOSTNo
Security keys and saltswp-config.phpOptional, logs everyone out
Dashboard user passwordswp_users tableSeparate task

How do you test the change?

Load your homepage and log in to the dashboard; if both work, the new password is correct, and if you see a database connection error, recheck the password in wp-config.php.

Also check:

  • Front-end pages and a few posts.
  • The admin area, including saving a draft.
  • Scheduled tasks and contact forms.
  • Any other app that connects to the same database, such as a staging site or external script.

Clear your page cache so you do not see an old cached copy that hides a problem.

What if you see a database connection error?

A database connection error after the change almost always means the password in wp-config.php does not exactly match the one set on the server, so copy it again carefully.

Common causes:

  • A typo or extra space in DB_PASSWORD.
  • Special characters breaking the PHP string.
  • You changed the password for a different database user.
  • The file did not save because of permissions. See fixing unable to write to wp-config.php.
  • Your host caches PHP configuration and needs a minute to pick up the change.

If nothing works, set the password again on the server using simple letters and numbers, then update the file. Our guide on fixing Error establishing a database connection covers other causes.

Should you also change security keys?

Changing the security keys and salts in wp-config.php is a good extra step after a breach, because it forces every logged-in user, including attackers, to sign in again.

You can generate fresh values from the WordPress secret key service and paste them over the existing AUTH_KEY to NONCE_SALT lines.

Everyone will be logged out, so do this at a quiet time. Then reset admin passwords if you suspect any account was compromised.

How do you keep database credentials safe?

Keep database credentials safe by limiting who can read wp-config.php, using a unique strong password, restricting database users to one database, and never sharing the file in support tickets or public repositories.

A few habits help:

  • Set strict file permissions on wp-config.php, often 400 or 440, if your host supports it.
  • Give each site its own database user.
  • Store credentials in a password manager, not email.
  • Remove old database users you no longer need.
  • Review which database users exist every few months and check that each one is still in use.
  • Keep remote database access turned off unless an app truly needs it.

These steps reduce the damage if one site or account is ever exposed.

If you manage many sites, keep a simple record of when each database password was last changed and who has access. That record makes it much faster to respond when a contractor leaves or a security alert arrives.

Finally, remember that a strong database password does not replace other protection. Keep WordPress core, plugins and themes updated, use a firewall, and keep off-site backups so you can recover quickly if something goes wrong.

Frequently asked questions

Where is the WordPress database password stored?

It is stored in the wp-config file in your site's root folder, on the line that defines DB_PASSWORD. The same password is also set for the database user on your MySQL or MariaDB server. Both values must match for WordPress to connect.

Will changing the database password log out users?

No. Changing the database password does not affect logged-in users or their dashboard passwords. Users are only logged out if you also change the security keys and salts in your configuration file.

Can I change the database password from the WordPress dashboard?

No. WordPress has no dashboard setting for the database password. You must change it in your hosting panel or database tool, then edit the configuration file through a file manager, SFTP or SSH.

What happens if the database password is wrong?

WordPress cannot connect to the database and shows Error establishing a database connection on every page. Fix it by making the password in the configuration file match the one set for the database user on your server.

How often should I change my WordPress database password?

Change it whenever someone who had access leaves, after any security incident, or if the password was weak. Many site owners have no fixed schedule, but a strong unique password and limited file access matter more than frequent changes.

Sources

  1. wp-config.php WordPress Developer Resources
  2. ALTER USER Statement MySQL Reference Manual
  3. MySQL Databases cPanel Docs
  4. WordPress Secret Key Service WordPress.org

Is your product missing, or something out of date?

Tell us what to add or correct. We read every note and reply when we need a source. A message does not buy a ranking.

About the editors

Written and checked byWPLegible Editorial Team Independent WordPress reviews and guides

Researched from the primary sources listed above and checked against our editorial rules before publishing.