Categories: TutorialsUbuntu

Reset the WordPress Admin Password Using CLI (via 2 Methods)

WordPress is a popular CMS for bloggers and journalists, offering a range of features, including multi-user management, allowing admins to create separate accounts for different users with varying privileges.

Sponsored

The rule of thumb is to hand over the username and password to the user after account creation, but if the user or admin itself forgets the own password, the only option is to reset the user or admin password from the MySQL console or by using external tools.

In this article, I’ll show you how to reset (or change) the WordPress logins using the MySQL command-line client or the “wp-cli” command.

Method 1: Reset the WordPress Password via MySQL Command

The first step is to log in to your server running WordPress via SSH. Then, make sure to take a backup of your WordPress database. You can either create a snapshot of your server or use the backup option if you are using a hosting provider.

Alternatively, you can use the following command to export a specific MySQL database to an SQL file format by providing the MySQL username, password, and database name.

$ sudo mysqldump -u [user] -p [db_name] > [export_the_db.sql]

Once you have taken the backup, you can reset the WordPress password by first connecting to the MySQL or MariaDB server.

$ mysql -u [user] -p

Output:

Then you need to select the WordPress database; if you forget the database name, you can use the “SHOW DATABASES;” SQL query to list all MySQL databases. Once you locate the correct database, use the following command to select it:

MySQL> use [wordpress_db]

Output:

Then, for confirmation, you can run the following command to list all WordPress users:

MySQL> select user_login from wp_users;

Output:

I have only one user account named “linuxtldr“, whose password I want to change. However, in your case, there could be one or more users, so note down the username and execute the following SQL query to update that user password (using the MD5 hashing algorithm):

📝
Make sure all highlighted green fields are replaced with accurate information.
MySQL> UPDATE `wp_users` SET `user_pass` = MD5('changeme') WHERE `user_login` = 'wordpress-user';

Output:

Sponsored

When you are done, quit the MySQL console using the “exit” SQL query and return to WordPress to log in with the updated password.

Method 2: Reset the WordPress Password via WP-CLI Command

WP-CLI is a fantastic command-line tool for managing WordPress that you should definitely give a try. We’ve already covered its installation and command-line usage in a separate article, so we’ll skip those parts and focus on resetting the WordPress administrator password.

First, ensure you are connected to the system running WordPress, then open your terminal and navigate to the directory where the WordPress files are stored (typically, it’s “/var/www/html“).

Then run the following command to list all the WordPress user accounts:

$ wp user list

Output:

Finally, select the username whose password you want to change, and pass it to the command below, along with the new password for resetting.

📝
Make sure the green highlighted fields are replaced with the correct information.
$ wp user update wordpress-user --user_pass=changeme

Output:

That’s it; you have successfully changed the WordPress password using the “wp-cli” tool.

Final Word

All the methods mentioned would work for resetting the WordPress password; you can choose one according to your preference. If you have any questions, feel free to ask them in the comments.

Till then, peace!

The post Reset the WordPress Admin Password Using CLI (via 2 Methods) appeared first on Linux TLDR.

Ubuntu Server Admin

Recent Posts

How to Install and Use Zig Programming Language on Ubuntu or Debian Linux

In this article, we will see how to install and use zig programming language on…

47 minutes ago

Linux Sed Tutorial: Learn Text Editing with Syntax and Examples

This article was adapted from its original version on NixCraft. Sed is an acronym for…

7 hours ago

How to Fix VMware’s “Could not open /dev/vmmon” Error on Ubuntu

You’ve recently installed VMware Workstation on your Ubuntu system and encountered the frustrating “Could not…

14 hours ago

How to Fix Ubuntu 404 Errors While Fetching Dependencies

Have you ever found yourself staring at a terminal full of 404 errors while trying…

14 hours ago

How to Fix ‘Please Install All Available Updates’ Error When Upgrading Ubuntu 18.04 to 20.04 LTS

One particularly frustrating error that many users face when trying to upgrade from Ubuntu 18.04 …

14 hours ago

How to fix “Release is not valid yet” Error in Docker Containers

In the world of containerization, time synchronization issues can create unexpected roadblocks when working with…

14 hours ago