How to Change WordPress Admin Password via MySQL

Changing or editing a WordPress Admin password is a superuser-oriented activity. In such a case, you can still log in to the WordPress website account and edit the other existing user profile information or even further customize the site information.

However, for one reason or another, you might feel like the integrity or security of your admin passwords has been compromised. It could also be due to a site security policy put in place by the company represented by the WordPress site where admin user passwords are changed weekly or monthly.

[ You might also like: How to Create New WordPress Admin User via MySQL ]

The MySQL command line or shell environment is a fast, effective, and direct way of changing the WordPress Admin password especially if you don’t want to interact with the WordPress Admin GUI environment to make these security changes or you are in a Linux server environment without direct access to a graphical web interface such as phpMyAdmin.

Checking WordPress User and Metadata via MySQL

Log in to the MySQL database from the Linux command line with your username and password.

$ mysql -u wordpress -p

Next, access the wordpress database, and list database table that holds all users is called wp_users.

MariaDB [(none)]> use wordpress;
MariaDB [(none)]> select * from wp_users;
Check WordPress Users
Check WordPress Users

Identify the user whose password you need to change. In this case, we will try to change the admin password for user editor@linuxshelltips.com. To be sure that this user has the Admin user status under their profile, let us access another WordPress database table called wp_usermeta.

MariaDB [(none)]> select * from wp_usermeta;
Check WordPress User Metadata
Check WordPress User Metadata

The table column meta_value with column values 10 and a:1:{s:13:”administrator”;b:1;} and the table column meta_key with column values wp_capabilities and wp_user_level should all be linked to the table column user_id with column value 3 which is the ID of the editor@linuxshelltips user under table wp_users.

The stated column values under table column meta_value and meta_key imply that the associated WordPress user through the specified ID-to-user_id match has admin privileges on the WordPress site.

Changing the WordPress Admin Password via MySQL

The SQL statement to use should be similar to the following:

MariaDB [(none)]> UPDATE 'database_name'.'database_table_name' SET 'database_table_column' = MD5( 'your_new_password' ) WHERE 'database_table_name'.'database_table_column' = "your_admin_username";

From the above MySQL command syntax, changing the password for user editor@linuxshelltips can be translated to the following SQL statement:

MariaDB [(none)]> UPDATE wordpress.wp_users SET user_pass = MD5( 'Id@diff3pass') WHERE wp_users.user_login = "editor@linuxshelltips";

Alternatively, the SQL statement’s WHERE cause could reference this user’s ID in the MySQL database.

MariaDB [(none)]> UPDATE wordpress.wp_users SET user_pass = MD5('Id@diff3pass') WHERE wp_users.
Change WordPress Admin Password via MySQL
Change WordPress Admin Password via MySQL

As per the above screenshot, the query execution was a success. It’s now time to test our new Admin user password on the WordPress site.

Login to WordPress Admin with New Password
Log in to WordPress Admin with New Password
WordPress Custimization
WordPress Customization

We managed to change the password of this WordPress Admin user successfully and even logged in with the new credentials to confirm that the user still retained admin access to the site. Also, we confirmed that this user still has the ability to make site customization changes; a role that is not granted to an ordinary site user.

The flexibility that comes with changing the WordPress Admin user password is important as sometimes the WordPress GUI interface may be unresponsive and you need to implement new Admin user credentials by the time the site is up and running. Also, you get to effectively manage all other Admin users’ access to the WordPress site.

Got something to say? Join the discussion.