Random Linux

Linux, video games and web hosting

If you forget the login to the WordPress dashboard and the “forgot your password” link isn’t working for you, it is possible to change it from the command line. First, you will want to find the database that WordPress is using, so go to the folder that holds it, and get that from the wp-config.php file.

#]grep -i db wp-config.php

That will show you the database information from that file. It will come out like this.  All that you will need for what we are doing is the database name, which is db_name.

[email protected] [/home/user/public_html]# grep -i db wp-config.php
define(‘DB_NAME’, ‘db_name’);
define(‘DB_USER’, ‘db_user’);
define(‘DB_PASSWORD’, ‘yourdbpw’);
define(‘DB_HOST’, ‘localhost’);
define(‘DB_CHARSET’, ‘utf8’);
define(‘DB_COLLATE’, ”);

Then, you will need to drop into the mysql command line using that database.

#]mysql db_name

After that, you will want to list the users that are in the database to get some of the information that you will need to change the password.

mysql>select * from wp_users;

That will show the users and the ids for the users, which will look something like this.

| ID | user_login | user_pass                          | user_nicename | user_email                | user_url                | user_registered     | user_activation_key | user_status | display_name |
|  1 | Admin      | dOInlojhdE93LpD/kdiascxpItw33Ld/ | admin         | [email protected] |                         | 2011-01-06 08:08:52 |                     |           0 | Admin        |
|  2 | user2      | dOInlojhdE93LpD/kdiascxpItw33Ld/ | user2         | [email protected]        | http://www.yoursite.com | 2011-01-11 22:27:31 |                     |           0 | User2        |
2 rows in set (0.00 sec)

Finally, it’s time to change the password. You will use the id number in the first column of the user you need to change in this command. If we are changing the user admin with the id number 1, we would use this.

mysql> update wp_users set user_pass = MD5('password') where ID = 1;

Now, you should be able to log into the dashboard with the username and whatever you put in the place of password.

January 28th, 2011

Posted In: MySQL

One Comment

Leave a Reply

Your email address will not be published. Required fields are marked *