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

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

Reset mysql admin password using cli

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.

See also  GNOME 46 Released! New Global Search, Remote Login, and More

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:

Connecting to mysql server

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:

Selecting wordpress database

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

MySQL> select user_login from wp_users;

Output:

Listing wordpress username

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):

See also  Setting up Linux Containers (LXC)
Sponsored
📝
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:

Updating wordpress user password in mysql command

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:

Listing wordpress users

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

See also  How to Find the total size of all files in a directory in Ubuntu
📝
Make sure the green highlighted fields are replaced with the correct information.
$ wp user update wordpress-user --user_pass=changeme

Output:

Changing wordpress login password using wp-cli

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.


Discover more from Ubuntu-Server.com

Subscribe to get the latest posts sent to your email.

Comments

No comments yet. Why don’t you start the discussion?

    Leave a Reply