How to reset WordPress Admin Password via MySQL Command Line

Step 1 : Generating MD5 hash for WordPress admin password

  1. Try to change the current password admin123 to wpadmin123.Create a file called wp.txt, containing nothing but the new password.
  2. # vi wp.txt
wppw1
wppw2
  1. Run the below command to get the MD5 string.
  2. # tr -d ‘\r\n’ < wp.txt | md5sum | tr -d '-'
wppw3
  1. Now you will get the MD5 string of the new password wpadmin123 that you have saved in the file wp.txt.
  2. Please save the MD5 string locally.
  3. Run the below command to remove the file wp.txt.
  4. # rm -rf wp.txt
wppw4

Step 2 : Updating the admin password through MySQL using the newly generated MD5 hash string

  1. Log in to MySQL with the below command.
  2. # mysql -u root -p
wppw5
  1. Enter your MySQL password.
wppw6
  1. Run the below commands to use the WordPress database and show the table name with wp_users. Here we are using the below database and user for testing.
  2. WordPress DB: wordpress
  3. WordPress User: wp_user
  4. > use wordpress;
  5. > show tables;
wppw7
  1. Run the below command to get an idea of what’s going on inside.
  2. > SELECT ID, user_login, user_pass FROM wp_users;
wppw8
  1. From here you can see the MD5 string of the current password of the database WordPress.
  2. Now you can reset the password of your WordPress admin with the below command.
  3. > UPDATE wp_users SET user_pass=('8221bbe0c8e475a295b7533c047a68c7') WHERE user_login = 'admin';
wppw9
  1. Now check with the below command if the password has changed.
  2. > SELECT ID, user_login, user_pass FROM wp_users;
wppw10

About Damon Luong

San Jose, California
This entry was posted in My Linux. Bookmark the permalink.