Question

Reseting WordPress admin password via the command line (terminal)

I’ve seen this question a lot where people have forgotten their WordPress admin password and they don’t remember their email in order to use the “Lost Password” feature.

The password can be changed/reset from MySQL/MariaDB using the command line.


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

alexdo
Site Moderator
Site Moderator badge
December 10, 2019
Accepted Answer

First you need to identify the table responsible for storing WordPress user accounts. Usually the table that stores all user information is wp_users but you may have different database prefix so you can check your wp-config.php file and search for the following line:

$table_prefix = 'wp_';

Also you need to know the name of the database as well. You can get this information from wp-config.php as well. You need to check these lines:

define( 'DB_NAME', 'digital_ocean' );
define( 'DB_USER', 'digital_ocean' );
define( 'DB_PASSWORD', 'RANDOMPASS' );
define( 'DB_HOST', 'localhost' );

Now when you know the table prefix and the database.

1. You need to access MySQL

# mysql -u root -p
MariaDB [(none)]> show databases;
MariaDB [(none)]> use digital_ocean;

2. You can query the wp_users table to retrieve all the needed information:

MariaDB [(none)]> SELECT ID, user_login, user_pass FROM wp_users;
+----+--------------+------------------------------------+
| ID | user_login   | user_pass                          |
+----+--------------+------------------------------------+
|  1 | digitalocean | $P$lkasflsakhflkashflkashlkfhasfkl |
+----+--------------+------------------------------------+
1 row in set (0.00 sec)

3. Now you need to generate a MD5 generated password in order to change/reset the password. There is two ways to generate update the password.

The first one is to create a MD5 hashed password via the command line:

# echo -n "password" | md5sum

Replace the “password” string used in this example with your own strong password.

Now you need to update the password using the following query:

MariaDB [(none)]> UPDATE wp_users SET user_pass= "5f4dcc3b5aa765d61d8327deb882cf99" WHERE ID = 1;

Now you should be able to access the WordPress admin area using the new password

The other method is to update the password without using any MD5 password generator:

MariaDB [(none)]> UPDATE wp_users SET user_pass = MD5('password') WHERE ID=1;

You need the change the password string with the actual password you want to use.

Once the query is executed you should be able to login using the new password.

I hope this helps.

Regards, Alex

alexdo
Site Moderator
Site Moderator badge
September 6, 2020

Hi, @saud968

Are you logged as the root user in the MySQL console? Make sure that you do not have any typos as well.

show databases;

and

SHOW DATABASES

should work just fine for you.

Hope that this helps! Regards, Alex

thanks. really helpful info

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.