How to change WordPress admin password through command line.

MySQL older versions(<<5.x)

1.You will have to generate an MD5 hash of your desired password. You can generate one from here

http://www.miraclesalad.com/webtools/md5.php

2. Get access to MySQL command prompt.

#mysql -u root -p
Enter password:

Enter the mysql root password.

3. Get the list of databases currently on your server.

mysql>SHOW databases;

+--------------------+
| Database           |
+--------------------+
| information_schema |
| cphulkd            |
| eximstats          |
| foryou_wp          |
| horde              |
| leechprotect       |
| modsec             |
| mysql              |
| performance_schema |
| roundcube          |
| whmxfer            |
+--------------------+
11 rows in set (0.00 sec)

mysql>

4. Select your wordpress database ( here it is foryou_wp)

mysql> use foryou_wp;
Database changed
mysql>

5. Find the table name with ‘users’ at the end ( here it is wp_users)

mysql> show tables;
+------------------------+
| Tables_in_foryou_wp    |
+------------------------+
| wp_commentmeta         |
| wp_comments            |
| wp_links               |
| wp_options             |
| wp_postmeta            |
| wp_posts               |
| wp_term_relationships  |
| wp_term_taxonomy       |
| wp_terms               |
| wp_usermeta            |
| wp_users               |
+------------------------+
11 rows in set (0.00 sec)

mysql>

6. To get the details about the user, user ID etc; enter the following command.

mysql> SELECT ID, user_login, user_pass FROM wp_users;
+----+------------+------------------------------------+
| ID | user_login | user_pass                          |
+----+------------+------------------------------------+
| 1  | admin      | d51b9f2635741a855162826d2e13185c   |
+----+------------+------------------------------------+
1 row in set (0.00 sec)

mysql>

7. Update the new password with the following command.

UPDATE (name-of-table-you-found) SET user_pass="(MD5-string-you-made)" WHERE ID = (id#- of-account-you-are-reseting-password-for);

Command should look like:

mysql>UPDATE wp_users SET user_pass="f367084816d16de2660a1d1493c0a62c" WHERE ID = 1;

8. Make sure that the password has changed.

mysql> SELECT ID, user_login, user_pass FROM wp_users;
+----+------------+------------------------------------+
| ID | user_login | user_pass                          |
+----+------------+------------------------------------+
| 1  | admin      | f367084816d16de2660a1d1493c0a62c   |
+----+------------+------------------------------------+
1 row in set (0.00 sec)
mysql>

9. Quit from mysql prompt.

mysql>quit
Bye
root@server [~]#

MySQL recent versions (5.x)

Skip step 1 and replace the step 7 with following.

mysql>UPDATE (name-of-table-you-found) SET user_pass = MD5('"(new-password)"') WHERE ID = (id#-of-account-you-are-reseting-password-for);

Command should look like:

mysql> UPDATE wp_users SET user_pass = MD5 ('Qwerty123') WHERE ID = 1;
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0

mysql>

That’s it!