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.

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.

×
2 answers

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

thanks. really helpful info

Submit an Answer