Change WordPress password directly in database

If you are stupid enough, as I am, you will need to do this. Yes, my WordPress couldn’t send an email to reset my password and I’ve forgot it. Long story short, I had to change it, without PhpMyAdmin since I’m using a self hosted WP.

First, I had to find the name od the database, username and password, which is easy to find in wp-config.php file in your WP dir. Next login to MySQL/MariaDB:

Login:

mysql -u root -p

List databases:

MYSQL> SHOW DATABASES; 

Select database:

MYSQL> USE database.name; 

List tables:

MYSQL> SHOW TABLES; 

wp_users is the default name of the table you’ll be editing, although your table might be named different

List columns:

MYSQL> SHOW COLUMNS FROM wp_users; 

Select column:

MYSQL> SELECT * FROM wp_users; 

This should give you output like this:

The field user.pass contains your password in encrypted MD5 format

Change you password:

MYSQL> UPDATE wp_users set user_pass = MD5('your.new.password') where id = 1;

Enter your new password and actual ID number, listed in the first column

Check if your password has changed:

MYSQL> select * from wp_users where id = 1;

Leave a Comment

Tested on Ubuntu & Pop OS