We see many situations when users forget their WordPress passwords and are not able to recover them. So we will show in this article how you can reset the WP password for a specific user. We will assume you are a server administrator.
How to reset a WordPress password with Linux/MySQL commands
1. Locate the wp-config.php file and extract database name
WP keeps the MySQL connection details in the wp-config.php file. We want to extract the DB_NAME and table_prefix values. Navigate to the WP installation folder and run:
grep -i 'DB_NAME\|$table_prefix' wp-config.php
[root@web wp]# grep -i 'DB_NAME\|$table_prefix' wp-config.php define( 'DB_NAME', 'plothost_wp805' ); $table_prefix = 'wpy2_'; [root@web wp]#
In our case, the database name is plothost_wp805 and the table prefix is wpy2_ . We need these values for the next step.
2. Update the user password
Now we will run a MySQL command to update the password for the admin user (you can also use this command for other users):
mysql -e "UPDATE WORDPRESSDATABASE.TABLEPREFIX_users SET user_pass = MD5('NEWPASSWORD') WHERE user_login = 'admin';
WORDPRESSDATABASE is the DB_NAME value from the previous step.
TABLEPREFIX is the $table_prefix value from the previous step.
[root@web wp]# mysql -e "UPDATE plothost_wp805.wpy2_users SET user_pass = MD5('27bSucokCBRJuhyKJcQF') WHERE user_login = 'admin';"
If there are no issues, the command will not return anything. The new password is set, try to log into WordPress admin area.
How to create a WordPress admin with Linux/MySQL commands
mysql -e command