How To Update a WordPress Password Through MySQL

Description

There are plenty of tutorials on how to update a password (password required when you to to http://yourdomain.com/wp-admin) for a WordPress installation through phpMyAdmin, but there are not many that will do it for those who want to be a little bit more robust and try it through a command line. This tutorial is going to show both. First the easy way through phpMyAdmin and then all through command line.

phpMyAdmin

Step 1: Find the Right Database

Log into your cpanel and determine the appropriate database for your WordPress. Browse to the directory where the your WordPress is installed and look for a file called wp-config.php. Open the wp-config.php and look for the lines that look like the following:

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'username_wrd2');

/** MySQL database username */
define('DB_USER', 'username_wrd2');

/** MySQL database password */
define('DB_PASSWORD', 'database_user_password');

/** MySQL hostname */
define('DB_HOST', 'localhost');

This shows us that the database name (DB_NAME) is username_wrd2.

Step 2: Open phpMyAdmin.

  • Log into the CPanel and select phpMyAdmin.
  • Select the appropriate database on the top left of the screen. The database naming schema for most hosts is username_. This is why we want to find the right database to use from step one. For the example we are using username_wrd2 and phpMyAdmin will just show it as _wrd2. Select _wrd2
  • There will now be a list of tables in the database. Click wrd2_users.



Step 3: Edit the User Information

Once you click the wp_users link there will be a list of all the users associated with your WordPress. Find the row with the user you want to change the password.

  • Click edit for the user for whom you want to change the password.

  • Now all the information for that user should be showing and all you have to do is change the password.
  • Select MD5 for the password encryption type. MD5 is what WoordPress will use by default.
  • Click GO in the bottom left corner of the user section and now the new password should be saved. You can now go to http://yourdomain.com/wp-admin and log in with the new credentials.

Command Line

Step 1: Connect to the right database.

The wp-config.php file contains the right database, username, and password that are needed in order to log into mysql.

mysql -u <username> -h <host> -p 
Enter password: 

Then from the wp-config.php file we know the database that we want to connect to and thus implement the following command.

mysql>use <database>;

Step 2: Show current users and update password for right user.

mysql> SELECT * FROM wp_users;
+----+--------------+------------------------------------+---------------+-----------------------------+-------------------------+---------------------+----------------------+-------------+--------------+
| ID | user_login   | user_pass                          | user_nicename | user_email                  | user_url                | user_registered     | user_activation_key  | user_status | display_name |
+----+--------------+------------------------------------+---------------+-----------------------------+-------------------------+---------------------+----------------------+-------------+--------------+
|  1 | admin        | 1fab43ee6db8eeb65a2bd8f5ed354500a5 | admin         | youremail@domain.com | http://www.yourdomain.com | 2010-01-11 23:15:05 | Daa5960a123FF55e594be |           0 | John Doe  |

+----+--------------+------------------------------------+---------------+-----------------------------+-------------------------+---------------------+----------------------+-------------+--------------+

Then all you need to do to update the password in mysql is the following command. Note however, you can choose whatever kind of encryption you would like. For this example I am encoding in an md5sum.

mysql>UPDATE wp_users set user_pass=MD5("YourNewPassword") WHERE user_login = "username";
SELECT * FROM wp_users;

Comments are closed.