How To Reset WordPress Admin Password using MySQL Command Line

WordPress is a very popular and sought after open source CMS. This CMS is written in PHP. This tool is fairly simple and reliable to use.
However, while working, you may encounter such a problem as password management, and you can simply forget it. Without a key password, you will not be able to administer your site. Here’s how you can change your WordPress password. Changing the password will be done using the MySQL database.

Reset WordPress admin password

First, you need to be logged in with administrator rights to your MySQL. This is required in order to use the MySQL command line tool. The WordPress SQL record credentials are stored in a file called wp-config.php at the root of your website. To do this, you need the following lines inside a file called wp-config.php:

define('DB_NAME', 'myWordpressDB');
define('DB_USER', 'myUserName');
define('DB_PASSWORD', 'aVeryStrongPassword');
$table_prefix  = 'wp_';

You will then be able to use this information to log into MySQL and make the necessary changes. Before moving on, we’ll make a full backup of the database:

mysqldump -umyUserName -paVeryStrongPassword myWordpressDB | gzip -9 > myWordpressDB.sql.gz

The next step is to log into your MySQL database. You can do it like this:

mysql -umyUserName -paVeryStrongPassword

A list of available databases will be displayed:

show databases;

 +--------------------+
 | Database           |
 +--------------------+
 | myWordpressDB      |
 | information_schema |
 +--------------------+

Of all the existing ones, you need to choose myWordpressDB. Enter the following command:

use myWordpressDB;

Once you have successfully identified your WordPress base, you need to list all WordPress users along with their ID, username, and encrypted password:

SELECT ID, user_login, user_pass FROM wp_users;
+----+------------+------------------------------------+
| ID | user_login | user_pass                          |
+----+------------+------------------------------------+
|  1 | admin      | FGpPqio82fIYCZK$P$B0cVrK0Wh7A.7NK/ |
|  2 | name       | $P$BCFybroBJDFuv1oQdLIWcNp8jMCmsl1 |
+----+------------+------------------------------------+

The first ID (1) is the priority and belongs to the main WordPress admin. Therefore, the password will be reset exactly to ID 1

UPDATE wp_users SET user_pass=MD5('YourNewStrongPassword') WHERE ID = 1;

After the procedure was successful, you can see that the user admin (1) already has a new password

+----+------------+------------------------------------+
| ID | user_login | user_pass                          |
+----+------------+------------------------------------+
|  1 | admin      | 00a95b8f755edd93daa0f3fdfb476936   |
|  2 | alex       | $P$BCFybroBJDFuv1oQdLIWcNp8jMCmsl1 |
+----+------------+------------------------------------+

By default WordPress uses PasswordHash to encrypt the user’s password, which hashes it using 8 MD5 passes. However, the default MD5 hash is also acceptable, so this method works.

Was this article helpful?

Related Articles

Leave A Comment?