How to update WordPress Admin Password via MySQL Command Prompt
- Step 1 :-
You will need to create a MD5 Hash version of the new password that will be assigned to the account, by issuing the below command.
You can replace the “newpass” string used in this example with your own strong password and Copy the password MD5 hash to a file in order to later paste the hash to MySQL user password field.
echo -n "newpass" | md5sum
- Step 2 :-
Once you’ve generated the new password MD5 hash, log in to MySQL database with root privileges and run the below command in order to identify and select the WordPress database. In this case WordPress database is named “wordpress”.
mysql -u root -p MariaDB [(none)]> show databases; MariaDB [(none)]> use wordpress;
- Step 3 :-
To identify the table responsible for storing WordPress user accounts, you can run the below command. Usually the wp_users table is stored all user information.
We can query the wp_users table to retrieve all users ID, login name and password and identify the username ID field of the account that needs the password changed and the username ID value will be used again while updating the password.
MariaDB [(none)]> show tables; MariaDB [(none)]> SELECT ID, user_login, user_pass FROM wp_users;
Once you correctly identified the ID of the user that needs the password changed, you can use the below command to update his password. Replace the user ID and password MD5 Hash accordingly
- Step 4 :-
Here, the user ID is 1 and the new password hash is: e6053eb8d35e02ae40beeeacef203c1a.
MariaDB [(none)]> UPDATE wp_users SET user_pass= "e6053eb8d35e02ae40beeeacef203c1a" WHERE ID = 1;
If you don’t have an already MD5 hashed password, you can use MySQL UPDATE command with the password written in plain text as same as in the below example.
Here, we use MySQL MD5() function to calculate the MD5 hash of the password string.
MariaDB [(none)]> UPDATE wp_users SET user_pass = MD5('the_new_password') WHERE ID=1;
- Step 5 :-
To retrieve this user database information, you can query the wp_users table with the ID of the user that you’ve changed the password once the password has been updated.
MariaDB [(none)]> SELECT ID, user_login, user_pass FROM wp_users WHERE ID = 1;
That’s it 🙂
Please cross check it from your end and let me know if you have any question or assistance on this.