Resetting Your WordPress Admin Password via Command-Line: A Step-by-Step Guide

Resetting your WordPress login through the shell can be efficiently accomplished using either the MySQL command-line client mysql or the wp-cli command-line interface. These tools allow you to manage WordPress instances directly from the shell.

Updating Your WordPress Password Using MySQL

Begin by securely logging into your server through SSH. Before making any changes, it’s crucial to ensure you have a recent backup of your database to safeguard against potential issues.

To connect to your MySQL or MariaDB server, use the MySQL command-line tool:

mysql -u username -p

Replace username with your MySQL username. You will be prompted to enter your password to proceed.

After successfully logging in, select your WordPress database:

use wordpress_db;

Be sure to replace wordpress_db with the actual name of your database.

Next, execute the following SQL query to update the user password, taking into account that WordPress utilizes the MD5 hashing algorithm:

UPDATE `wp_users` SET `user_pass` = MD5('newpassword') WHERE `user_login` = 'yourusername';

Substitute newpassword with your new desired password and yourusername with your WordPress username.

Finally, exit the MySQL prompt by typing:

exit

Resetting the WordPress Admin Password with wp-cli

The wp-cli command serves as an even simpler method to reset the WordPress administrator password.

Begin by logging into your server using SSH. If wp-cli is not installed, follow the detailed installation guide.

Once installed, use the following wp-cli command to reset the password:

wp user update username --user_pass=newpassword

Here, replace username with your WordPress username and newpassword with your new password.

FAQ

  • Q: What should I do if I don’t know my database name?
    A: You can find the database name in the wp-config.php file located in your WordPress installation directory. Look for the line that reads define('DB_NAME', 'database_name');.
  • Q: Is it safe to use MD5 for password hashing?
    A: While WordPress historically used MD5 hashing, it’s generally recommended to use more secure hashing methods. WP-CLI and later WordPress versions handle password hashing securely in the backend.
  • Q: How can I confirm if wp-cli is installed?
    A: Run wp --info from the command line. If it’s installed, you will see version details. Otherwise, you will receive a command not found error.
  • Q: Can I reset the password of another user account?
    A: Yes, both methods allow you to update any WordPress user as long as you have the username.