A WP site comprises at least two users – a database user and a regular user. While creating a WordPress user, you grant the permission to modify, drop DB tables, and create new tables. If you are using a one-click WordPress installer tool such as Softaculos, StackScripts, or a similar tool, the software will grant the DB access permission to the user behind the scenes.
Once you or the one-click installer have created the user, you or the one-click installer will modify the WordPress configuration file. WP Config is an important file as it has the database username, password, security keys, name, and DB prefix. If someone gets a copy of this file, the user may misuse the details.
The user may log in to the DB and delete important website tables or modify the records without leaving a trace. The user may also reset the user password. If the user’s login credential is incorrect, you’ll see a DB-related error i.e. error establishing a database connection. Below, we’ve shared a tutorial to reset/change/update the WP user and the admin password.
Either use PHPMyAdmin or a terminal to log in to the MySQL DB server. If you’re using PHPMyAdmin, find your website’s database from the list of DB PHPMyAdmin displays on the left side and click on it. If you’re using the terminal, run this command
mysql -u root -p and enter the
MySQL admin password. Once you’re logged in, choose the website DB using the
use database_name command.
Now, to change the user secret phrase/word, run the below SQL query after replacing the wp_user_name with the WordPress DB username you’ve put in the WordPress configuration file, and the user_pwd with the new password.
ALTER USER IF EXISTS'wp_user_name'@'localhost' IDENTIFIED BY 'user_pwd';
What will the above MySQL alter query do? The above query will first check if the user name that you have replaced wp_user_name with is present in the MySQL user table or not. If the user exists, the query will change the user’s password. Once the above query is executed successfully, run the
FLUSH PRIVILEGES command. Once you have changed the password, update the config file with the new secret word/phrase and check if the error establishing the database connection error is gone.
The WordPress content management system has a “forgot password” page. Through this page, you can only reset the user’s secret word/phrase. If WordPress is not sending email, you won’t get the reset password link to your inbox.
Like the MySQL database, WP has a user table where it stores the users you’ve created with its “add users” tool and the user that WP has created during the installation and setup of the WordPress content management system. If you lost access to the admin, you can modify the entries of the WordPress user table. If you have forgotten the user email or name, you can replace or update the same.
User name, email ID, display name, and URL are in plain text format, but the password is encrypted. To update the same, you can run the below query after changing the enter_your_pwd_here with your new secret word/phrase and the user_login with the user name you were using to log in to your WordPress site (if the user is present in the wp_users table):
update wp_users set user_pass= MD5('enter_your_pwd_here') where user_login="your_wp_user_name";
If the user is missing, create a new user by running the below query:
insert into wp_users(user_login,display_name,user_pass,user_nicename,user_email, user_registered) values('your_user_name','your_display_name', MD5('your_pwd'),'your_nice_name','your_email', now());
|Replace the string in column 1 with this in the above query
|Valid email address
Now, you will have to update the wp_usermeta table’s entry for the site administrator. To do so, note down the ID of the user you’ve created using the above query (run
select * from wp_users query to see the entries of the wp_users table) and run the following query after replacing id_you_have_copied with the new user’s ID:
update wp_usermeta set user_id="id_you_have_copied" where instr(meta_value,"admin") >0