[SOLVED] Unable to successfully update WordPress admin password via MySql command line

Issue

I’m trying to change the admin password for my WordPress site manually, by editing the wp-config.php and using the mySql command line(linux) as follows:

I change this line in wp-config.php in var/www/html/wordpress:

define('DB_PASSWORD','myNewPassword');

Then I update the wordpress database in mySql like this:

update wp_users set user_pass = md5('myNewPassword') where id = 1;  

(I tried without the md5 as well, still doesn’t work)

After verifying that the change was made, I close my browser, and then try to login to my wordpress site, but I keep getting this error:

Error Establishing a Database Connection

When I change the password back to the old one, it works fine again.

Here are my version numbers:

Red Hat Enterprise Linux Server release 6.9 
wordpress Version 4.9.1
php version 5.6.14
mysql version 14.14 Distrib 5.6.36 for Linux(x86_64)

Are there any steps I’m missing?

Thanks!

Solution

First of all: don’t touch this line define('DB_PASSWORD','some_password');. It’s not users password, it’s password to connect your mysql server.

The error you got Error Establishing a Database Connection occurred because of changing constantabove.

From wordpress codex sql command:

UPDATE (name-of-table-you-found) SET user_pass = MD5('(new-password)') WHERE ID = (id#-of-account-you-are-reseting-password-for);

So, your command will be:

//if your wordpress db tables prefix is `wp_`, then.
UPDATE wp_users SET user_pass = md5('myNewPassword') where id = 1;  

If database table prefix is something else, then run command like:

UPDATE yourWebsitePrefix_users SET user_pass = md5('myNewPassword') where id = 1;  

Also, make sure, that the password you’re trying to change belong to the user with id=1. If your user id is, for ex. 27, then run this:

UPDATE wp_users SET user_pass = md5('myNewPassword') where id = 27;  

Answered By – Samvel Aleqsanyan

Answer Checked By – Clifford M. (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published.