Home » Wordpress » WordPress : Add an admin user to database and Reset User Roles

WordPress : Add an admin user to database and Reset User Roles

In wordpress when some hacking occures or some illegal activity and want to restore the fuctionality then the default admin user may not work. If the default admin user deleted from the database also then you cannot login into the wp-admin backend of wordpress blog. To solve this problem you must manually add a new user to the blog through inserting certain values into the database. Generally PhpMyAdmin is used to do this or use the mysql command shell also.

First locate the database of wordpress. The database name, username and password of the database is on the wp-config.php file. Find the lines given below in wp-config.php

/** The name of the database for WordPress */
 define('DB_NAME', 'yourdb_wp');
/** MySQL database username */
     define('DB_USER', 'youruser');
/** MySQL database password */
     define('DB_PASSWORD', 'yourpassword');

Then select the database from the database select menu in phpMyAdmin. Your database will be loaded and you will now see a list of your database tables. You will need to change the wp_users and the wp_usermeta table. Click on the wp_users table to bring up the data for that table. You should see a list of the current users come up – or if you do not have any users you will see the list of database fields available. Click Insert in the top to insert values into this table. The field names and description are given below.

Creating User by Editing wp_users table

  1. user_login – this is the username you want to use to access WordPress
  2. user_pass – this is the password you want to use to access WordPress (be sure to select MD5 from the phpMyAdmin Function menu – WordPress stores passwords with MD5 encryption)
  3. user_nicename – put whatever you would like to refer to yourself as in here (not your username)
  4. user_email – this is the email account associated with this user
  5. user_url – the url to your website like – http://smashingweb.info
  6. user_registered – when was this user registered – just select a date with the date selector or enter the date.
  7. user_activation_key – you can leave this blank — There is no activation key needed
  8. user_status – leave this set to 0
  9. display_name – put a name to display on the admin panel and on the posts.

Now hit the Go button. The value is inserted into the table and you will get a user_id from the field ID. Take that and keep written.

If there are no errors continue with editing the wp_usermeta table. Some values in this table is required to get the added user working with  administrator privilages. that is user level 10.

Creating User Privilages by Editing the wp_usermeta table


Now we just created a user by inserting values. Next is we will need to give it privileges to access the WordPress Admin seciton. This is done through the wp_usermeta table. You will need to know the id of the user you just created.We will need to insert two rows into the wp_usermeta table, wp_capabilities and wp_user_level. Here are the steps you will need to follow to give your user privileges.

  1. Click on the wp_usermeta table to bring up the entries.
  2. Click on the “Insert” tab to insert a new row.
  3. Fill in the following data.
    1. umeta_id – leave this blank it is automatically generated
    2. user_id – this is the id of your inserted user (this id will get from the wp_users table ID field)
    3. meta_key – for this step insert wp_capabilities
    4. meta_value – insert exactly this – a:1:{s:13:"administrator";s:1:"1";}
  4. Then press Go. The value is inserted into this table.
  5. Insert another row with the data given below
    1. umeta_id – leave this blank it is automatically generated
    2. user_id – this is the id of your inserted user (this id will get from the wp_users table ID field)
    3. meta_key – for this step insert wp_user_level
    4. meta_value – insert 10
  6. Click the “Go” button in phpMyAdmin to insert the row.

Now you can login with the new inserted user from the wp-admin login page with the username and password specified. After login just go to the Users section and edit on your profile then click update profile button on the bottom. Now wordpress will create some other keys in the tables and have a “clean up” the user just added through backend.

Still some problem persists You can just navigate to wp_options table and find wp_user_roles entry in the option name field Just update the option value given below.



Generally this is not needed but in some special cases to fix the user roles and permissions in wordpress this will help. Still more problems then drop a query here.

That is it – Added a new user through database in wordpress.

Enhanced by Zemanta

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.