Skip to content

How to Reset WordPress Admin Password via MySQL Command Prompt

Share

Reading Time: 3 minutes

Locked out of your WordPress admin? No panic—if you have database access, you can reset the admin password quickly from the MySQL/MariaDB command prompt. This method is fast and reliable when you can’t use the “Lost your password?” link or don’t have WP-CLI. Below are clear, safe steps and a few cautions so you don’t accidentally break anything.

Reset WordPress Admin Password via MySQL Command Prompt

1 — Prepare: locate database credentials

Before touching the database, find your WordPress database name and DB user. On the server, open the site’s wp-config.php (usually in the WordPress root):

cat /path/to/your/site/wp-config.php | grep DB_NAME
cat /path/to/your/site/wp-config.php | grep DB_USER

Note the DB_NAME, DB_USER, and DB_PASSWORD. Also note the $table_prefix (often wp_) — you’ll need the correct users table name (e.g., wp_users).


2 — Connect to MySQL / MariaDB

Open the MySQL prompt using the database credentials (run as a user that can access the WP database, often root or the DB user from wp-config.php):

mysql -u root -p

or, if connecting with the WordPress DB user and password:

mysql -u DB_USER -pDB_PASSWORD DB_NAME

(If you pass -p without the password, MySQL will prompt you—safer than showing the password in the shell.)

If you connected without specifying the database, select it now:

USE your_database_name;

3 — Identify the admin user

Find the user record you want to reset. Commonly the admin username is admin, but it could be different. Query the users table:

SELECT ID, user_login, user_email FROM wp_users WHERE user_login='admin';

Or list all users to find the right account:

SELECT ID, user_login, user_email FROM wp_users;

Note the ID and user_login for the account you’ll update.


4 — Reset the password (safe and compatible method)

WordPress stores passwords using the PHPass hashing system. Historically people used MD5() in MySQL which was accepted and rehashed on first login, but the recommended approach now is to generate a secure password hash or use a trusted single-query approach. Two common options:

Option A — Quick (MD5 fallback)
This works and WordPress will automatically rehash the password the next time the user logs in. Replace newStrongPassword123 with a secure password:

UPDATE wp_users
SET user_pass = MD5('newStrongPassword123')
WHERE user_login = 'admin';

Option B — Generate a PHPass hash outside MySQL (recommended for long-term compatibility)
Create a PHP script that uses WordPress functions to generate the hash, or use WP-CLI (if available):

With WP-CLI:

wp user update admin --user_pass='newStrongPassword123'

If WP-CLI is not available and you prefer a single MySQL query, Option A is usually sufficient—WordPress will accept the MD5 entry and update it on login.


5 — Verify the change

To ensure the update went through, run:

SELECT ID, user_login, user_pass FROM wp_users WHERE user_login='admin';

You’ll see a different value in user_pass (MD5 hash or whatever hash you set). Now try logging into wp-admin with the new password.


6 — Clean up & security tips

  1. After you regain access, immediately go to Users → Your Profile and change the password again via WordPress to ensure it’s stored using the latest phpass hash.
  2. If you used a temporary password, require a stronger password and enable two-factor authentication.
  3. Check the user_email for the account and confirm it’s still correct. If not, update it from the Users screen.
  4. Remove any temporary scripts you created to generate hashes.

Troubleshooting

  • If you get permission errors when connecting to MySQL, use a DB admin account (often root) or ask your hosting provider for access.
  • If the table prefix isn’t wp_, replace wp_users with yourprefix_users.
  • If the site uses external authentication or an SSO plugin, resetting the DB password may not affect login—check your authentication plugins.

Resetting a WordPress admin password from the MySQL prompt is a powerful, last-resort option—fast and effective when you have server access. Always take care: back up the database (or at least the wp_users table) before making changes, and harden the account after you’re back in.

You can find Linux Tutorials on this page

You can also find all Video Tutorial on Youtube

Follow us on Facebook Twitter X Reddit Quora Linkedin Tubmblr Youtube


Share

Leave a Reply

Your email address will not be published. Required fields are marked *

?>