How to reset your WordPress forgotten password

A few days ago I was unable to log into one of my wordpress installations, it was just one of those days, I simply didn’t remember my password, so for those of you that are going through a similar situation, here is a way to regain access:

Log into your server via ssh and then log into mysql:

mysql -u root -p

It is important to know the id of the user you want to reset the password for, I will show you an example using a username “testuser”:

SELECT ID, user_login FROM wp_users WHERE user_login=’testuser’;

The result should look similar to this:

+—-+————+
| ID | user_login |
+—-+————+
| 8 | testuser|
+—-+————+
1 row in set (0.00 sec)

If you don’t know the username or if you get no hits as a result to the above command, an option would be to go through all users that have the word “testuser” in them, so we’ll use an SQL query for this:

SELECT ID, user_login FROM wp_users WHERE user_login LIKE ‘%testuser%’;

This will show you all rows that have the word “testuser” in them.

Ok, now that we have the id we’ll proceed to reset the password for the user testuser with id 8 which can be done using the following query:

UPDATE wp_users SET user_pass=md5(‘newpassword’) WHERE ID=8;

See that the number 8 at the end of the line specifies the id, so  change that to whatever id you got earlier.

Once you’ve reset the password here you should be able to log back into your WordPress installation with it.